字典和列表生成式

There are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.

可以简化基于可迭代对象创建列表或字典的语法结构。

列表生成式List Comprehension

语法:[条件表达式  for i in iterable]

 

迭代字典的方法

  方法一:最佳使用方式

复制代码
 1 for key in info:
 2     print(key,info[key])
 3     
 4 stu1102 aaaaa
 5 stu003 b
 6 stu004 c
 7 3 4
 8 1 None
 9 new setdefault value
10 111 222

复制代码

  方法二: #会先把dict转成list,数据里大时莫用

复制代码
 1 for k,v in info.items():
 2     print(k,v)
 3     
 4 stu1102 aaaaa
 5 stu003 b
 6 stu004 c
 7 3 4
 8 1 None
 9 new setdefault value
10 111 222
复制代码

字典的属性介绍: http://www.cnblogs.com/zoe233/articles/7017393.html

posted on 2017-08-24 14:53  Zoe233  阅读(213)  评论(0)    收藏  举报