我的代码看起来像这样:
documents=set()
finals = []
temporary_set= set()
temporary_set.add(i)
finals.append(documents.intersection(temporary_set))
当我想从我使用的决赛列表中获取所有值时:
for final in finals:
print (final)
然而,这会将项目作为列表中的集合项目返回。像这样:
[{27309053}, {23625724}, {25051134}]
我怎样才能使大括号被省略并且我的结果看起来像这样:
[27309053, 23625724, 25051134]
???
最佳答案
你可以改变
finals.append(documents.intersection(temporary_set))
到
finals.extend(documents.intersection(temporary_set))
这会将交集的每个元素添加到列表中,而不是交集本身。
关于python - 从 python 中的集合列表中删除大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53213550/