python - 从 python 中的集合列表中删除大括号

标签 python list set curly-braces

我的代码看起来像这样:

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/

相关文章:

java - 通过 ImmutableSet.copyOf() 和 new HashSet<>(list) 将列表转换为集合;

c++ - 如何组合来自 std::set 的成对元素?

python - 将集合列表转换为集合集合(以查找唯一元素)

python - Flask:AttributeError: 'UnboundField' 对象没有属性 '__call__'?

python - os.system ('TASKKILL/F/IM EXCEL.exe' ) 在 python 中

python - 为什么 random.shuffle(list(range(n))) 有效,但 random.shuffle(range(n)) 无效?

python - 如何在python中交叉2个二维数组?

python - 变换多项式图 - 乘以值列表

python - exec() 不适用于 unicode 字符

python - 以 "XX to XX"格式打印嵌套列表