+ 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

14th Sep 2020, 7:56 AM
Julian Yang
Julian Yang - avatar
9 Answers
+ 3
I always use append.
14th Sep 2020, 8:00 AM
Olivia
Olivia - avatar
+ 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
14th Sep 2020, 8:09 AM
Olivia
Olivia - avatar
+ 2
Append only adds an item @ the end of the list
14th Sep 2020, 8:02 AM
Programmado
Programmado - avatar
+ 2
Julian Yang could you explain what your asking for?
14th Sep 2020, 8:04 AM
Olivia
Olivia - avatar
+ 2
Kisakye Emmanuel so can we use + to insert element anywhere in list?
14th Sep 2020, 8:09 AM
Abhay
Abhay - avatar
+ 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
14th Sep 2020, 8:10 AM
Abhay
Abhay - avatar
0
Olivia thx btw, if i want to make it loop back to the start what to use?
14th Sep 2020, 8:01 AM
Julian Yang
Julian Yang - avatar
0
Olivia i want to make that after line 9 on my post it loop back to line 1 and do the process again
14th Sep 2020, 8:06 AM
Julian Yang
Julian Yang - avatar
14th Sep 2020, 8:11 AM
Julian Yang
Julian Yang - avatar