Text
I just came up with the nastiest Python list comprehension ever.
Here it is in all its glory:
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]
I apologize in advance to anyone who will try to understand what this function does and how it works. Hint: It returns a bunch of numbers which have a certain mathematical property.
Actually, its results are not perfect: It throws in a few false positives. I tried to fix it to remove the false positives; I can easily write code that will filter the false positives away, but I want any extra code to live up to the unidiomatism level of the list comprehension itself. That’s not an easy task :)
Does anyone have a suggestion on how to do it?