take the following as an example, which could work well. But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? def test(): l = [1, 2, 3, 4, 5, 6, 7, 8] return iter(l) def main(): for i in test(): print(i)