python的字典dict 遍历和赋值操作
import pdb if __name__ == "__main__": #创建字典 dic = {"url1":"http://www.qq.com","url2":"http://id.qq.com"} #更新字典 dic["url3"] = "http://qzone.qq.com" #遍历字典 for key in dic.keys(): if key == "url1": #更新字典 dic[key] = "http://www.qq.com/wenle" #遍历字典 for key,value in dic.iteritems(): print "key:[%s],value:[%s]"%(key,value) #遍历字典 for key in dic.iterkeys(): print "key:[%s]"%(key) #遍历字典 for value in dic.itervalues(): print "value:[%s]"%(value)