Predict the output of the following c∅de in Python.
l=[i for i in (j for j in (k for k in (x for x in range(1,11))))]
print(l)
Explain your answer.
Answers
Answered by
9
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Explanation:
Given,
lst = [i for i in (j for j in (k for k in (x for x in range(1, 11))))]
> [i for i in (j for j in (k for k in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))]
> [i for i in (j for j in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])]
> [i for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]
> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- First a list is generated consisting of numbers 1 to 10.
- Then it is copied over to another list which is again copied to another list and so on.
- Finally, the list is displayed displayed.
Similar questions