John Smith John Smith - 3 months ago 9
Python Question

Add values to array in one line

How can I write this code in one-line?

aa = []
for s in complete:
aa.append(s)


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

Answer

like this (be care with strings):

aa.extend(complete)

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