Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Author picked up a quite convenient example to show methods/lambda superiority.

I prefer list/set/dict comprehensions any day. It's more general, doesn't require to know a myriad of different methods (which could not exists for all collections, PHP and JS are especially bad with this) and easily extendable to nested loops.

Yes it could be `[for line in text.splitlines() if line: for word in line.split(): word.upper()]`. But it is what it is. BTW I bet rust variant would be quite elaborate.



I'm a big fan of Python syntax, but really comprehensions don't make any sense to me efficiency wise (even for readability). Python syntax would become perfect with filter() and map() :')


With judicious use of generators, and with itertools [0] when needed, they can be quite efficient for not much effort.

And these are flexible tools that you can take with you across projects.

[0] https://docs.python.org/3/library/itertools.html


> I prefer list/set/dict comprehensions any day. It's more general, doesn't require to know a myriad of different methods

It's the opposite, your knowledge of the standard set of folding algorithms (maps, filters, folds, traversals) is transferable almost verbatim across a wide range of languages: https://hoogletranslate.com/?q=map&type=by-algo


maps and filters maybe. Other stuff is a wild west.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: