Python Language Extract values one by one


Example

Start with iter() built-in to get iterator over iterable and use next() to get elements one by one until StopIteration is raised signifying the end:

s = {1, 2}   # or list or generator or even iterator
i = iter(s)  # get iterator
a = next(i)  # a = 1
b = next(i)  # b = 2
c = next(i)  # raises StopIteration