Doing things in one line?
Scott Anderson
sanderson at ttm.com
Mon Jan 3 12:24:23 EST 2000
Actually, just search the mailing list archives back just before the
holidays, because I asked that very question. There were about 30
responses IIRC so I'm not going to summarize them here. :-)
Here's a one-liner I did the other day for the heck of it:
reduce(lambda x, y: x + y, range(1, int(raw_input('Enter a number: ')) +
1))
It accepts a number from the user and adds 1 to it. :-)
Regards,
-scott
gerrit.holl at pobox.com wrote:
>
> Hello,
>
> I know there's a FAQ entry called "Can I write obfuscated one-liners
> in Python?", but for fun, I'm trying to do it now.
>
> Can I do this in one line:
> if a: foo()
> elif b: bar()
> else: foobar()
>
> Is it possible with an intelligent construct that looks like:
> a and foo() or a and bar() or foobar()
More information about the Python-list
mailing list