Doing things in one line?

Michael Hudson mwh21 at cam.ac.uk
Thu Jan 13 12:29:29 EST 2000


Scott Anderson <sanderson at ttm.com> writes:

> 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. :-)
> 

No it doesn't. It computes the nth "triangular number", where n is the
number the user enters.

Or it dies if the user enters a number less than 1.

Cheers,
Michael



More information about the Python-list mailing list