Feb-24-2022, 11:38 PM
(This post was last modified: Feb-24-2022, 11:41 PM by Gribouillis.)
Skaperen Wrote:this needs to work with whatever iterator it gets.You want something that is structurally impossible. Consider the following iterator
def user_inputs(): while True: yield input("Give me a string: ") iterator = user_inputs()Now 'iterator' is empty iff the user decides not to type the Enter key until the program exits. There is no way for the program to read the user's mind. Even if the program calls
next(iterator)
, the answer will be known only if this call returns before the program exits.