John Smith John Smith - 1 year ago 106
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download