Clever hack or code abomination?

Roy Smith roy at panix.com
Wed Nov 30 22:15:27 EST 2011


I need to try a bunch of names in sequence until I find one that works 
(definition of "works" is unimportant).  The algorithm is:

1) Given a base name, "foo", first see if just plain "foo" works.

2) If not, try "foo-1", "foo-2", and so on

3) If you reach "foo-20", give up.

What would you say if you saw this:

for suffix in [''] + [str(i) for i in xrange(-1, -20, -1)]:

It generates the right sequence of strings.  But, if you came upon that 
code, would it make sense to you, or would you spend half the afternoon 
trying to figure out what it did and the other half of the afternoon 
ranting about the deranged lunatic who wrote it?



More information about the Python-list mailing list