Clever hack or code abomination?

Matt Joiner anacrolix at gmail.com
Wed Nov 30 22:49:46 EST 2011


def possible_names():
    yield "foo"
    for i in range(20):
        yield "foo-" + str(i)

ಠ_ಠ

On Thu, Dec 1, 2011 at 2:15 PM, Roy Smith <roy at panix.com> wrote:
> 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?
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list