[issue41774] While removing element from list using for and remove(), which has same items output is not right

Raymond Hettinger report at bugs.python.org
Fri Sep 25 14:37:27 EDT 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

Sorry for the wording of the last message.  Go ahead with whatever you would like do :-) 

Was only trying to point-out that the generator semantics don't interact nicely with slice assignments:

    $ python3.9 -m timeit -s 'a=list(range(1000))' 'b=a[:]' 'b[:]=(x for x in a)'
    5000 loops, best of 5: 46.6 usec per loop

    $ python3.9 -m timeit -s 'a=list(range(1000))' 'b=a[:]' 'b[:]=[x for x in a]'
    10000 loops, best of 5: 26.3 usec per loop

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41774>
_______________________________________


More information about the Python-bugs-list mailing list