python 字典的用法
1. 创建一个空字典
dict = {}
2. 判断字典中有无目标索引
if a in dict
3. 字典中索引的值加一
dict['a'] = dict.get('a', 0) + 1
4. 将字典写入csv文件
writer = csv.writer(csvfile) for key, value in dict.items(): writer.writerow([key, value])
5. 当字典的value是一个list时候
if name not in task: task[name] = []
往list里增加数据
exit = {}
exit.setdefault(col[0],[]).append(col[1])
如果两个字典有相同索引,继续比较其list中有无交集
for i in exit.keys(): for j in exithis.keys(): if j == i: result = list(set(exit[i]).intersection(set(exithis[j]))) if result: print(i) print(result)