How to Return an Iterator From a Tuple in Python


In this example, we will learn how to return an iterator from a tuple and print each value in Python.

Source Code

my_tuple = ('a', 'b', 'c')
my_iter = iter(my_tuple)

print(next(my_iter))
print(next(my_iter))
print(next(my_iter))

Output:

a
b
c
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement