[New-bugs-announce] [issue22446] Shortening code in abc.py
Ram Rachum
report at bugs.python.org
Fri Sep 19 22:30:20 CEST 2014
New submission from Ram Rachum:
Can't this code:
class Sequence(Sized, Iterable, Container):
# ...
def __contains__(self, value):
for v in self:
if v == value:
return True
return False
Be shortened into this:
class Sequence(Sized, Iterable, Container):
# ...
def __contains__(self, value):
return any(item == value for value in self)
Which can even fit on one line with a lambda:
class Sequence(Sized, Iterable, Container):
# ...
__contains__ = lambda self: any(item == value for value in self)
----------
components: Library (Lib)
messages: 227117
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Shortening code in abc.py
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22446>
_______________________________________
More information about the New-bugs-announce
mailing list