for x in alist: blist = blist + x in python

The code for x in alist: blist = blist + x iterates over the elements in alist and assigns each element to the variable x. The code then concatenates the value of x to blist, effectively appending each element in alist to blist.

Here is an example:

main.py
alist = [1, 2, 3]
blist = []

for x in alist:
  blist = blist + [x]

print(blist) # prints [1, 2, 3]
101 chars
8 lines

Alternatively, we can use the shorthand += operator for list concatenation to achieve the same result:

main.py
alist = [1, 2, 3]
blist = []

for x in alist:
  blist += [x]

print(blist) # prints [1, 2, 3]
94 chars
8 lines

Note that the brackets [x] are necessary to concatenate a single element to a list.

gistlibby LogSnag