python 快速调换字典key,value值,字典推导式,列表推导式

字典推导式
mcase = {'a': 10, 'b': 34}
mcase_frequency = {v: k for k, v in mcase.items()}
print mcase_frequency
#  Output: {10: 'a', 34: 'b'}

列表推导式

multiples = [i for i in range(30) if i % 3 is 0]
print(multiples)
# Output: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]

猜你喜欢

转载自blog.csdn.net/qq_42091922/article/details/87916023