【发布时间】:2019-02-24 10:39:10
【问题描述】:
我有一个列表 queue 和一个迭代器对象 neighbors 我想将其元素附加到列表中。
queue = [1]
neighbor = T.neighbors(1) #neighbor is a <dict_keyiterator at 0x16843d03368>
print(list(neighbor)) #Output: [2, 3]
queue.extend([n for n in neighbor])
print(queue)
输出:
[1]
预期输出:
[1, 2, 3]
出了什么问题?
【问题讨论】:
-
试试:
queue.extend(list(neighbor)) -
那行不通。
标签: python