+ 1
Is it better to use + or append to add word to empty list?
Im trying to make a simple program to list who attend the class https://code.sololearn.com/chtn0jtJNOlk/?ref=app https://code.sololearn.com/chtn0jtJNOlk/?ref=app
9 Answers
+ 3
I always use append.
+ 3
Oh, you can just put the whole thing in a while loop, have a variable to measure how many loops you want it to run or if you want it to go on forever then do while x==x for example
+ 2
Append only adds an item @ the end of the list
+ 2
Julian Yang could you explain what your asking for?
+ 2
Kisakye Emmanuel so can we use + to insert element anywhere in list?
+ 1
Here is a performance difference for both operations
import timeit
start=timeit.default_timer()
b=[]
b+="a"
print(timeit.default_timer()-start)
start=timeit.default_timer()
b=[]
b.append("a")
print(timeit.default_timer()-start)
Append seems much faster in this case
0
Olivia thx btw, if i want to make it loop back to the start what to use?
0
Olivia i want to make that after line 9 on my post it loop back to line 1 and do the process again
0