You can also do this one-liner which works without adding any new functions (though you need to import itertools):
print [zip(*v)[1] for v in [list(v) for k, v in itertools.groupby(sorted([(''.join(sorted(s1 + s2)), (s1, s2)) for s1 in states for s2 in states if s1 < s2], key=lambda v: v[0]), lambda v: v[0])] if len(v) > 1]
Of course, that’s clearly crossing the line from “clever” into “obfuscated”, but oh well. It was fun to write. :)
Adam Atlas - 2007-10-31 10:28:25
You can also do this one-liner which works without adding any new functions (though you need to import itertools):
print [zip(*v)[1] for v in [list(v) for k, v in itertools.groupby(sorted([(''.join(sorted(s1 + s2)), (s1, s2)) for s1 in states for s2 in states if s1 < s2], key=lambda v: v[0]), lambda v: v[0])] if len(v) > 1]Of course, that’s clearly crossing the line from “clever” into “obfuscated”, but oh well. It was fun to write. :)
anders pearson - Wed 31 Oct 2007 14:06:39
If you really enjoy this sort of thing, just get it over with and switch to Perl. Much better language for one-liners.
kat - Wed 31 Oct 2007 18:32:00
…and incomprehensibility.
;p