I just want to get a prime number list, but I find that the for loops more times than I image, it seems that the sequence don't change even though I modified the variable with the same name.
I try name nums as global, but nothing changed.
nums = list(range(2, 11))
count = 0
for num in nums:
nums = list(filter(lambda a: a == num or a % num, nums))
count += 1
print(count) # 9
print(nums)
I want nums = list...
can modify nums in for num in nums
, and the count is 4.
Thank you.