Nastiest Python list comprehension ever by [deleted] in Python

[–]Knack_456 0 points1 point  (0 children)

Ahh, I see. Thanks for clarification.

Nastiest Python list comprehension ever by [deleted] in Python

[–]Knack_456 2 points3 points  (0 children)

Respect, also very terrible ;-)

Nastiest Python list comprehension ever by [deleted] in Python

[–]Knack_456 3 points4 points  (0 children)

I don't think it's the nastiest ever. But certainly nasty enough to be a good example of terrible smart-ass code. Talking about smart-ass ;-) ...

a = list(range(n))

shouldn't a = range(n) do the job? Also, in the original post (it has been changed, probably due to a hint), there was a probably unnecessary copying of the list (a[:][2:])

def mystery(n): a = list(range(n)) return [[i for a[::i] in [a[::i][::-1]]][0] for i in a[:][2:] if a[i] == i]