A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039302.html below:

[Python-Dev] listcomps vs. for loops

[Python-Dev] listcomps vs. for loops [Python-Dev] listcomps vs. for loopsGuido van Rossum guido at python.org
Wed Oct 22 13:47:42 EDT 2003
> How about an until keyword in generator expressions:

New keywords are not on the table for generator expressions.  You
could do this with 'while' (which is just 'until not' -- note that
your example uses that :-) but I'd be against making this part of the
syntax more complex.  You can do that with itertools.takewhile or
dropwhile anyway.

> And we could have accumulators first() and last():
> 
> def first(it):
> 	return it.next()

This begs for using a plain old loop statement with a 'break'.

> def last(it):
> 	for value in it:
> 		pass
> 	return value

What if it is empty?

> first(line for line in file if line.startswith("#"))
> 
> if not last(file):
> 	# last line not terminated

The comment is incorrect.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4