defaultdict
需要构造类似{k1: {v11, v12, v13, ...}, k2: {v21, v22, v23, ...}, ...}结构的数据时,可以用collections.defaultdict:
from collections import defaultdict
a = defaultdict(set()) for i in range(100): a[i].append('test1')
a[i].append('test1')
逻辑选择语法
用and或or替换掉某些if else语句
a = 0 b = a if a else 0 b = a and 0 c = 1 d = c if not c else 1 d = c and 1
标签:defaultdict,...,Python,笔记,else,语法,test1,append From: https://www.cnblogs.com/roundfish/p/16666617.html