例一:生成10以内偶数列表
In [1]: evens = [i for i in range(10) if i % 2 == 0]
In [2]: evens
Out[2]: [0, 2, 4, 6, 8]
flattened = [i for row in matrix for i in row]
evens = [i for i in range(10) if i % 2 == 0]
chars = {w[0] for w in words_list}
带字典的:
changed = {value: key for key, value in input_dict.items()}
转载自:https://www.cnblogs.com/amiza/p/10159293.html