python中的items方法
items方法是将字典中所有的项以列表的形式返回,列表中的每一项都是以键值对的形式表现的。但其返回的次序可能不一样。
1 d={'title':'python web site ','url':'http://www.python.org','span':0}
2 d.items()
3 [('url','http://www.python.org'),('span',0),('title','python web site')]
iteritems方法和items的方法大致相同,但是其返回的是一个迭代器对象而不是如上的列表。
it=d.iteritems()
it//无效
list(it)
[('url','http://www.python.org'),('span',0),('title','python web site')]