a={'a':{'b':{'c':{'d':'e'}},'f':'g'},'h':'i'} def show(myMap): for str in myMap.keys(): secondDict=myMap[str] print str if type(myMap[str]).__name__=='dict': for key in secondDict.keys(): if type(secondDict[key]).__name__=='dict': print key show(seco
#!/usr/bin/python dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "##########
dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "###########items############
1 # 字典如下 2 movie = { 3 '妖猫传':['黄','染'], 4 '无问西东':['章','王'], 5 '超时空':['雷','佟'] 6 } 7 name = input('请输入演员的名字') # 收集信息 8 for i in movie: # 遍历字典movie的键名 9 actor = movie[i] # 设置一变量actor等于遍历的字典值 10 if name in actor: # 如果输入的演员名字在遍历的值中 11 print(name + '出演了'+
and 当俩个条件都满足时为True否为False or 任意一个条件满足时为True否为Flase not in 通常用于If语句,用来判断一个元素是否不在某个列表中 banned_user = ['andrew','carolina','david'] user = 'marie' if user not in banned_user: print(user.title()+',you can post a response if you wish.') If elif else 组合使用
favorite_language ={ "jen":"python", "sarah":"c", "edward":"ruby", "phil":"python", } for name in sorted(favorite_language.keys()):# sort by zimushunxu print(name.title()+&quo