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.py101 chars8 lines
Alternatively, we can use the shorthand += operator for list concatenation to achieve the same result:
main.py94 chars8 lines
Note that the brackets [x] are necessary to concatenate a single element to a list.
gistlibby LogSnag