4 ms·
omg. A comprehension for side effects only. That’s so horrible I wish I could see it. :)
by Waterluvian 4y ago
omg. A comprehension for side effects only. That’s so horrible I wish I could see it. :)
- leetrout 4y agoI worked with a guy that did this. Instead of writing for loops he would write comprehensions everywhere because "list comprehensions are pythonic". Think like: [send_welcome_email(u) for u in users] Just hanging out in the middle of the module or function.
- 83457 4y agoI prefer sent = [(u, send_welcome_email(u)) for u in users]
- Waterluvian 4y agoJust make the function return the argument passed into it. ;)
- Ultimatt 4y agoI prefer not_sent = users - {u for u in users if send_welcome_email(u)}
- 83457 4y agowoah
- BeetleB 4y agoI do it all the time :-) Just make sure it isn't consuming a lot of RAM and it's totally OK.