如何添加两组?
问题描述
a = {'a', 'b', 'c'}
b = {'d', 'e', 'f'}
我想添加以上两个设定值.我需要像
I want to add above two set values. I need output like
c = {'a', 'b', 'c', 'd', 'e', 'f'}
解决方案
你所要做的就是把它们结合起来
All you have to do to combine them is
c = a | b
集合是唯一值的无序序列.<代码>一个 |b 或 a.union(b)
是两个集合的并集(一个包含在任一集合中找到的所有值的新集合).这是一类称为设置操作"的操作,Python set
s 为提供方便的工具.
Sets are unordered sequences of unique values. a | b
or a.union(b)
is the union of the two sets (a new set with all values found in either set). This is a class of operation called a "set operation", which Python set
s provide convenient tools for.
相关文章