标签:style numbers span 推导 python2 focus dict bad class
推导式是个绝妙的东西,列表推导式一出,map、filter等函数黯然失色,自 Python2.7以后的版本,此特性扩展到了字典和集合身上,构建字典对象无需调用 dict 方法。
numbers = [1,2,3] d = dict([(number,number*2) for number in numbers])
good
numbers = [1, 2, 3] d = {number: number * 2 for number in numbers}
标签:style numbers span 推导 python2 focus dict bad class
原文地址:https://www.cnblogs.com/zzy-9318/p/10180511.html