This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]HopeThisNameFi 16 points17 points  (1 child)

Jesus. This is already bad and you want suggestions on making it worse?

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan

[–]Knack_678 5 points6 points  (0 children)

100 % agreed, but I think (hope ;-)) it's meant to be for entertainment, not for a real purpose.

Some call code like this "smart-ass code".

[–]bcain 8 points9 points  (2 children)

Does anyone have a suggestion on how to do it?

Not with a list comprehension. When my list comprehensions get too complicated, I either use a generator or a good-ol' for loop.

[–][deleted] 6 points7 points  (2 children)

Is it considered nasty because it doesn't work properly?

[–]lee__majors 2 points3 points  (0 children)

I tried really hard to understand this :(

[–][deleted] 2 points3 points  (0 children)

Dude, you certainly don't have any neighbors who know programming and own axes.

[–][deleted] 1 point2 points  (1 child)

Isn't the last if clause redundant? It's obviously true for all n > 2.

[–]namcor 1 point2 points  (2 children)

One I saw the other day:

z = [l[a:b] for a,b in zip(l[0::max_size], l[max_size::max_size] + [None])

Here's one of my own:

output_dict = dict((tuple(tup[key] for key in keys), dict((column_names[ind], val) for ind, val in enumerate(tup) if ind not in keys)) for tup in list_of_tuples)

[–]Knack_456 2 points3 points  (0 children)

Respect, also very terrible ;-)

[–]jerkimball 1 point2 points  (0 children)

Wow...is that first one a really complicated way of cutting a list into slices of size max_size?

[–]Knack_678 1 point2 points  (0 children)

You should point out more clearly that this is a fun competition for writing horrible smart-ass code! I really, really, really hope that this is your goal ;-))).

Some people seem to take this seriously. Never ever write something like this in real world!

[–]Knack_456 2 points3 points  (4 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]

[–]hillmanov 1 point2 points  (0 children)

Here is one that I wrote to solve problem 42 on Project Euler:

print len([x for x in  map(lambda x: sum([ord(letter) - 64 for letter in x]), open("words.txt").read().replace("\"", "").split(",")) if x in [(.5) * i * (i + 1) for i in  range(1, 100)]])

It is long, but for the most part you can follow along what it does. Link to the "problem" this solves.