vcbeaut 发表于 2021-1-15 16:07:14

词典合并

set1 = set()
set2 = set()
set1.add('str1')
set2.add('str2')

dict1 = {'a' : set1}
dict2 = {'a' : set2}

怎么高效合并成 {'a' : set('str1', 'str2')}?

°蓝鲤歌蓝 发表于 2021-1-15 16:10:54

如果是你上述具体代码,你想高效合并的话,一开始就不应该写这几句

set1 = set()
set2 = set()
set1.add('str1')
set2.add('str2')

dict1 = {'a' : set1}
dict2 = {'a' : set2}
直接写成
dict_ = {"a": set("str1", "str2")}
页: [1]
查看完整版本: 词典合并