[Tutor] Selecting from list

Jim Mooney cybervigilante at gmail.com
Fri Jul 19 19:30:50 CEST 2013


On 18 July 2013 22:09, Steven D'Aprano <steve at pearwood.info> wrote:

> A list comprehension *is* a loop. It even includes a "for" inside it.
>
True, but correct me if I'm wrong, I thought comprehensions proceeded
at close to  C speed, faster than a loop you could write normally, and
speed was the major requirement with 200K elements. Actually, the
second part, after excising the the 0 and len-1 indexes that would
cause an index error when checking for >1000, could be a
comprehension, too. But it was unclear what was desired. Can the
condition only occur once or multiple times, and do you want to just
test True/False, or get a list of the number-triplets that fulfill the
condition?

Anyway, I'll do it that way when I feel like it since I really like
list comprehensions. For some reason to do with my obfuscated brain, I
actually find them clearer than a fully-written-out loop ;')

Jim


More information about the Tutor mailing list