Dec-18-2016, 06:55 PM
(This post was last modified: Dec-18-2016, 06:56 PM by gblomqvist.)
Hi,
Say that I have these for-loops:
I want to translate it into a list comprehension (for fun, as an exercise
) , and I've come this far:
But I still need to add a newline character ('\n') after every iteration of the first loop. How do I do that? Is it even possible?
Thanks!
/gb
Say that I have these for-loops:
1 2 3 4 5 6 7 8 9 10 |
s = '' for y in range (a): for x in range (b): if (x, y) in some_collection: s + = 'x' else : s + = '-' s + = '\n' |

1 |
' '.join([' x ' if (x, y) in some_collection else ' - ' for y in range (a) for x in range (b)]) |
Thanks!
/gb