int_lis[:] = duplic_int_lis [int_firs]
表示分配duplic_int_lis [int_firs]
to的所有项目int_lis
,因此它希望您在 RHS 上传递一个可迭代/迭代器。
但是在您的情况下,您将其传递给不可迭代的,这是不正确的:
>>> lis = range(10)
>>> lis[:] = range(5)
>>> lis #all items of `lis` replaced with range(5)
[0, 1, 2, 3, 4]
>>> lis[:] = 5 #Non-iterable will raise an error.
Traceback (most recent call last):
File "<ipython-input-77-0704f8a4410d>", line 1, in <module>
lis[:] = 5
TypeError: can only assign an iterable
>>> lis[:] = 'foobar' #works for any iterable/iterator
>>> lis
['f', 'o', 'o', 'b', 'a', 'r']
由于您无法迭代整数,因此会出现错误。
>>> for x in 1: pass
Traceback (most recent call last):
File "<ipython-input-84-416802313c58>", line 1, in <module>
for x in 1:pass
TypeError: 'int' object is not iterable