▲ | davepeck 9 days ago | ||||||||||||||||||||||
Yeah. `join` has forever been backwards to me in Python and I still sometimes get it wrong the first time out. Comprehensions, though -- they are perfection. :-) | |||||||||||||||||||||||
▲ | pansa2 9 days ago | parent [-] | ||||||||||||||||||||||
IMO comprehensions like `[x**2 for x in range(4)]` would be better written as `[for x in range(4): x**2]`. That would make the mapping between a comprehension and the equivalent loop much clearer, especially once you use nested loops and/or conditionals. For example, to flatten a list of lists `l = [[1, 2], [3], [4, 5, 6]]`:
vs
| |||||||||||||||||||||||
|