On 9/1/2023 12:15 PM, Pierre Fortin via Python-list wrote:
Hi,

reversed() results are fine until iterated over, after which the
results are no longer available. This was discovered after using
something like this:

rev = reversed( sorted( list ) )
sr = sum( 1 for _ in rev )
# rev is now destroyed

So reversed() results can only be iterated once unlike sorted(), etc...

reversed() is an iterator these days:

>>> l1 = [1, 2, 3]
>>> rev = reversed( sorted( l1 ) )
>>> type(rev)
<class 'list_reverseiterator'>
>

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to