Posts: 4,646
Threads: 1,493
Joined: Sep 2016
is there a way to test if an iterator is empty without "consuming" any content in case it is not empty? does a true/false test accomplish this? i don't want to iterate them to a list because some may be too large or infinite.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
(Feb-23-2022, 12:59 AM)BashBedlam Wrote: When an iterator is empty it should return aStopIteration
what happens if it is
not empty?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
so the short answer to "is there a way ... ?" is "no".
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
(Feb-24-2022, 09:21 PM)BashBedlam Wrote: Would it help to roll you own iterator?
no. this needs to work with whatever iterator it gets.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
the code i was going to use this for gets an object passed via a method argument. it tests to see if it is an iterator using
isinstance(the_arg,collections.abc.Iterator)
then it would be nice to know if it is empty. but this is not essential to know. it could just handle things better, i'll still do the
if not
test in case i's an empty sequence.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.