python 列表推导式,生成器推导式,集合推导式,字典推导式简介
1.列表推导式
multiples = [i for i in range(30) if i % 2 is 0]
names = [[],[]]
multiples = [name for lst in names for name in lst if name.count('e') >= 2]
2.字典推导式
mcase = {'a': 10, 'b': 34}
mcase_frequency = {mcase[k]: k for k in mcase}
3.集合推导式
squared = {x**2 for x in [1, -1, 2]}
4.生成器推导式
multiples = (i for i in range(30) if i % 2 is 0)
生命很短,请让生活更精彩一些!