New submission from Дилян Палаузов <dilyan.palau...@aegee.org>:
Please make bool() on lists at least as fast as len() > 0 on lists is. The trivial approach would be to define __bool__ on lists, that do something like "True if self else False". python3 Python 3.6.3+ (heads/3.6-dirty:2b5cbbb13c, Nov 1 2017, 19:03:09) [GCC 6.4.1 20171025] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> timeit.timeit('len([]) > 0') 0.0983404889702797 >>> timeit.timeit('bool([])') 0.15502946823835373 >>> timeit.timeit('True if [] else False') 0.03108721226453781 >>> timeit.timeit('len([1]) > 0') 0.11656427383422852 >>> timeit.timeit('bool([1])') 0.19317257404327393 >>> timeit.timeit('True if [1] else False') 0.057590410113334656 ---------- messages: 307294 nosy: dilyan.palauzov priority: normal severity: normal status: open title: bool() vs len() > 0 on lists type: performance versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32180> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com