News for hackers. Stuff that matters.
Re:Python List Comprehensions Explained Visually by c3534l on Wednesday December 02, 2015 @07:41PM (#10666974)
Frankly, comprehensions are one of Python's worst features. Some properly implemented functional syntax would be both more readable and concise. Plus double-nested (I'm not sure what you'd call it) comrpehensions seem to be backwards. Rather than [ingredient for ingredient in recipe for recipe in cookbook] it's [ingredient for recipe in cookbook for ingredient in recipe] which makes it sound as if there's only going len(recipe) number of ingredients in your list. Plus it's so verbose and horizontal, half the time if you want descriptive names you're gonna write something so verbose it doesn't even make it that much more readable.
Re:Python List Comprehensions Explained Visually by has2k1 on Wednesday December 02, 2015 @09:59PM (#10667458)
When reading code I find comprehensions easier to comprehend than combinations of map, filter and reduce. That is considering that I played around with some Common-Lisp before getting into Python.

The parts in the comprehension

    [*wanted* *iteration(s?)* *condition?*]
compares well to

    *iterations(s?)*
        *condition?*
            *append wanted*
for normal looping behaviour without changing order of the iterations.

One of my favourite comprehensions is of the sort

    [item for item in items in for i in (0, 1)]
of course this can be the same as

    list(items) * 2
but the comprehension is more versatile

    [item for item in items in for i in (0, 1) if items[0] != 'a']
For most once the mental fog clears comprehensions become natural very quickly as they are not that far removed from normal loops.
Re:Python List Comprehensions Explained Visually by oinksoft on Wednesday December 02, 2015 @08:28PM (#10667134)
Haskell, Erlang, and Clojure all have sane lambdas (assuming that's what you mean by "properly implemented functional syntax"), and list comprehensions are useful and idiomatic in those languages. Agreed about sequence names feeling out-of-order in nested comprehensions in Python.
Re:Python List Comprehensions Explained Visually by darkerside on Wednesday December 02, 2015 @08:35PM (#10667158)
From the Zen of Python: > There should be one-- and preferably only one --obvious way to do it.

If you have something written as a simple for loop, there's a real danger that you're moving in the wrong direction by translating it into a list comprehension.

Re:Python List Comprehensions Explained Visually by iamsohungry on Wednesday December 02, 2015 @08:52PM (#10667224)
> Plus double-nested (I'm not sure what you'd call it) comrpehensions seem to be backwards.

Why are you even doing this? This isn't an acceptable way to write code.

> Plus it's so verbose and horizontal, half the time if you want descriptive names you're gonna write something so verbose it doesn't even make it that much more readable.

If your list comprehension is more than 80 characters wide, it's not because list comprehensions are bad, it's because you did something too complicated. Pull it into a function and name it so people know what the hell you're doing.