#Getting the last item of a large iterator

8 messages · Page 1 of 1 (latest)

astral summit
#

Hi guys. I want to get only the last item of an iterator with billions of items.
I've tried exhausting, using *_, last = iterator, more_itertools.last, converting to list or deque. But all of them are slow(time complexity of O(n) for all ??) Is there an efficient way to do that?

atomic garden
#

Don't use iterators if you only care about the last item?

astral summit
#

I guess then I might have to find a different way to reach my result.

atomic garden
#

Yup, don't think using an iterator is the right thing here. How is the iterator computed?

astral summit
#

gen=nx.shortest_simple_paths(G,source=start,target=end) networkx library. I have to find the last item which is the one with longest path.

astral summit
#

I've seen this but my graph isn't directed but there might be way around. I'll give it a go.