A RetroSearch Logo

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

Search Query:

Showing content from http://www.mail-archive.com/python-dev@python.org/msg29276.html below:

[Python-Dev] Conditional For Statements

I'd like to propose an addition to the for statement's syntax:

for {variable} in {iterable} if {condition}:
    {block}
which is equivalent to

for {variable} in {iterable}:
    if not {condition}:
        continue
    {block}

and

for {variable} in filter(lambda: {condition}, iterable):
    {block}

This would make the syntax closer to that of generators, which have
'for variable in iterable if condition', and would improve code
clarity by increased brevity and not negating boolean expressions.

Following are examples of current code with what the new code would
be, taken from the Python 3.0a5 tarball.

Demo/tkinter/guido/ss1.py:163:
for (x, y), cell in self.cells.items():
    if x <= 0 or y <= 0:
        continue
for (x, y), cell in self.cells.items() if x > 0 and y > 0:

Lib/encodings/__init__.py:91:
for modname in modnames:
    if not modname or '.' in modname:
        continue
for modname in modnames if modname and '.' not in modname:

Lib/idlelib/AutoExpand.py:70:
for w in wafter:
    if dict.get(w):
        continue
for w in wafter if w not in dict:

Lib/Cookie.py:483:
for K,V in items:
    if V == "": continue
    if K not in attrs: continue
for K,V in items if V != "" and K not in attrs:

Lib/hashlib.py:108:
for opensslFuncName in filter(lambda n: n.startswith('openssl_'),
dir(_hashlib)):
for opensslFuncName in dir(_hashlib) if opensslFuncName.startswith('openssl_'):

There are many more examples of this in the standard library, and
likely even more in production code.

I am not familiar with LL(1) parsing, so this may impossible under
that constraint.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

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