view raw
John Smith John Smith - 9 months ago 64
Python Question

Add values to array in one line

How can I write this code in one-line?

aa = []
for s in complete:

I know there are several solutions. I would really appreciate if you could write them down.


like this (be care with strings):


or with list comprehension:

aa = list(s for s in complete)

or if u want to copy list u can do follow:

aa = complete[:]
aa = complete.copy() # same
aa = list(complete) # same