I would like to know how to perform multiple commands in a list comprehension.
Can you give me an example for something simple like:
[print ("bla1") and print ("bla2") for i in list]
so for a list of 4 length 4 I would have:
bla1
bla2
bla1
bla2
bla1
bla2
bla1
bla2
Dtrangely enough I didn’t easily find it in the documentation. (If you can see an obvious reason why I didn’t and can let me know how should I search for such stuff that would be even better).
EDIT: OK, that was a very bad example according to comments.
I am interested in creating a new from an old one but I feel that I need two commands to do that. (not a simple print, of course).
For example. I have a list of lists, and I want to create a list that is a result of manipulation of the sublists.
Don’t use list comprehension for commands. List comprehensions are for creating lists, not for commands. Use a plain old loop:
List comprehensions are wonderful amazing things full of unicorns and chocolate, but they’re not a solution for everything.