0 0 votes Consider the following Python code:nums = [1, 2, 3] it = iter(nums) first = next(it) nums.append(4) second = list(it) nums.append(5) third = list(it) print(first, second, third)What is the output of the code above?1 [2, 3] [4, 5]1 [2, 3, 4] []1 [2, 3, 4] [5]1 [2, 3] [] Programming in Python goclasses goclasses-da-dpp goclasses-da-dpp-day-193 programming-in-python goclasses-python-&-dsa-practice-questions output + – GO Classes 89 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes The statement $\texttt{it = iter(nums)}$ creates an iterator over the list.The statement $\texttt{first = next(it)}$ takes the first value from the iterator.first = 1Now the iterator is positioned after $\texttt{1}$.Then $\texttt{nums.append(4)}$ adds $\texttt{4}$ before the remaining iterator values are consumed.So $\texttt{second = list(it)}$ collects the remaining values:[2, 3, 4]After this, the iterator is exhausted.Even though $\texttt{nums.append(5)}$ adds a new value later, the exhausted iterator cannot be reused.Therefore, $\texttt{third = list(it)}$ gives an empty list.The final output is:1 [2, 3, 4] []Correct Option: B GO Classes answered Jun 6 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.