标签: python python-3.x set
dic = {'a': {1, 2, 3}, 'b': {5, 6, 7}} print(dic['a'])
如何获得打印结果排除1(不删除)为:
{2,3}
答案 0 :(得分:7)
您可以从内部集合中减去{1}:
{1}
print(dic['a'] - {1}) {2, 3}
或者等效地,您可以使用difference:
difference
print(dic['a'].difference({1})) {2, 3}
您可以在sets — Unordered collections of unique elements