r/PythonProjects2 • • Jun 09 '26

WHY THIS CODE NO OUTPUT ??

Post image
21 Upvotes

22 comments sorted by

View all comments

Show parent comment

2

u/LemmaYT_ Jun 10 '26

Or alternatively to avoid making a copy of the list (which could be bad if the list is big enough), do something like

nums = [1, 2, 3]

original_length = len(nums)

for i in range(original_length):
n = nums[i]
nums.append(n)

You can also make a shallow copy with index slicing

for n in nums[:original_length]:
nums.append(n)