[issue22446] Shortening code in abc.py

2014-09-19 Thread Benjamin Peterson
Changes by Benjamin Peterson : -- resolution: -> rejected status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing

[issue22446] Shortening code in abc.py

2014-09-19 Thread Ram Rachum
Ram Rachum added the comment: Thanks for the clarification. Oh well, sad to see the more verbose code win, but I guess that's life. I tried on PyPy but the difference was even more pronounced, 0.008922450399566156 for the long version and 0.042124665810088044 for the short version. -

[issue22446] Shortening code in abc.py

2014-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Because in first case there is one iterator, iter(self), and in second case there are two iterators: iter(self) and iter((v == value for v in self)). -- ___ Python tracker _

[issue22446] Shortening code in abc.py

2014-09-19 Thread Ram Rachum
Ram Rachum added the comment: Oh. I wonder why `any` is slow like that, you'd figure it's be optimized. -- ___ Python tracker ___ ___

[issue22446] Shortening code in abc.py

2014-09-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This is slower. >>> import timeit >>> class A(list): ... def __contains__(self, value): ... for v in self: ... if v == value: ... return True ... return False ... >>> timeit.timeit('500 in x'

[issue22446] Shortening code in abc.py

2014-09-19 Thread Ram Rachum
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: clas