Nastiest Python list comprehension ever
blog.garlicsim.org
Nastiest Python list comprehension ever
1–10 of 55 posts
Re: Nastiest Python list comprehension ever
#2Nested comprehensions are one of the things I hate about Python actually. The functions in itertools are so much clearer. I can't really think of a good reason to use nested comprehensions... they become unreadable really fast!
Re: Nastiest Python list comprehension ever
#3Re: Nastiest Python list comprehension ever
#4Does that even run? :) Nested comprehensions are one of the things I hate about Python actually. The functions in itertools are so much clearer. I can't really think of a good reason to use nested comprehensions... they become unreadable really fast!
Re: Nastiest Python list comprehension ever
#5Yes, provide more details so I don't have to spend twenty minutes figuring out what it does.
(Going by my three-second-look gut feeling: It's the Sieve of Eratosthenes)
Re: Nastiest Python list comprehension ever
#6> Does anyone have a suggestion on how to do it? Yes, provide more details so I don't have to spend twenty minutes figuring out what it does. (Going by my three-second-look gut feeling: It's the Sieve of Eratosthenes)
The author wasn't kidding about it being nasty to read...
Re: Nastiest Python list comprehension ever
#7> Does anyone have a suggestion on how to do it? Yes, provide more details so I don't have to spend twenty minutes figuring out what it does. (Going by my three-second-look gut feeling: It's the Sieve of Eratosthenes)
> i for a[::i] in
Mind blown. How does assigning to an array even work? I'm guessing this is way-undefined-speak for setting elements, and I am simultaneously dazzled by its brilliance and horrified by its stupidity.
Re: Nastiest Python list comprehension ever
#8> Does anyone have a suggestion on how to do it? Yes, provide more details so I don't have to spend twenty minutes figuring out what it does. (Going by my three-second-look gut feeling: It's the Sieve of Eratosthenes)
Looking at it a bit more, it's sort-of-obvious that that's what it is, if you've seen the Sieve before. However: > i for a[::i] in Mind blown. How does assigning to an array even work? I'm guessing this is way-undefined-speak for setting elements, and I am simultaneously dazzled by its brilliance and horrified by its stupidity.
Re: Nastiest Python list comprehension ever
#9 >>> def mystery(n):
It's a buggy implementation of primes_below(n) through a sieve."There should be one - and preferably only one - obvious way to do it." And this ain't it.
Re: Nastiest Python list comprehension ever
#10> Does anyone have a suggestion on how to do it? Yes, provide more details so I don't have to spend twenty minutes figuring out what it does. (Going by my three-second-look gut feeling: It's the Sieve of Eratosthenes)
list(range(n)) as opposed to range(n)
and why the double indexing of a in i in a[:][2:] if a[i] == i].
Am I missing something ? I think it would work without those.Edit: Yo La Tengo. Deviousness aside the code is quite nice. It would be fun to optimize it but without breaking its spirit.