集合是无序的
list1=[i for i in range(10)]+[i for i in range(10)]print("My list is :",list1)MySet=set(list1)print("My set is:",MySet)MyTuple=tuple(list1)print("My tuple is:",MyTuple)HisSet=MySet.pop()YourSet=MySet.clear()print("Your Set is:",YourSet)print("His Set is:",HisSet)
字典 字典的基本操作
#字典应用示例dictA={"Apple":"苹果","Computer":"计算机","Mouse":"鼠标","Mobile":"手机"}print(list(dictA)) #将字典的键转换为list类型print(list(dictA.items())) #将字典的键和值组装成tuple,然后转换为listprint(list(dictA.keys())) #将字典的键转换为list类型print(list(dictA.values())) #将字典的值转换为list类型#engItem对应字典的键,chnItem对应字典的值#相当于一个tuple对应字典items()函数的一个个结果for engItem,chnItem in dictA.items():print(engItem,"-->",chnItem)wFile=open("..\ABC.txt","w",encoding="utf-8")print(dictA,file=wFile)wFile.close()
两个字典的相加
#两个字典的相加dicA={'a':1,'b':2,'c':3,'d':4,'f':"hello"}dicB={'b':3,'d':5,'e':7,'m':9,'k':'world'}def addDic(dicA,dicB):newDic={}for key in dicA:if dicB.get(key):newDic[key]=dicA[key]+dicB[key]else:newDic[key]=dicA[key]for key in dicB:if dicA.get(key):passelse:newDic[key]=dicB[key]return newDicprint(addDic(dicA,dicB))'''print(dic.items())#会把这些值弄成元组 。print(dic.keys)print(dic.values)print(list(dic.items()))#会把这些值弄成元组 。print(list(dic.keys))print(list(dic.values))#用item 的方法更加直观一些 。#找到年龄最大的人,并输出 。请找出程序中有什么问题 。person = {"李先生":18,"王先生":50,"张先生":20,"孙先生":22}for key in person.keys():print(key)for value in person.values():print(value)for item in person.items():print(item)for i in person:print(i)m='李先生'for key in person.keys():if person[m]<=person[key]:m=key# 把大的值赋给了mprint("最大的人是{},年龄是{} 。".format(m,person[m]))字典的输出通常也转化为列表 。因为字典太特殊了 。d ={123:"123", 456:"456", 789:"789"}key = []value = http://www.kingceram.com/post/[]for i in d.items():key.append(i[0])value.append(i[1])print(key)print(value)'''mydic={'地铁6号线': [('23', [4449, 4415, 8864]), ('25', [4364, 4350, 8714]), ('33', [4113, 4145, 8258]), ('29', [3786, 3990, 7776]), ('41', [3856, 3835, 7691]), ('27', [3722, 3920, 7642]), ('31', [3536, 3453, 6989]), ('35', [3477, 3468, 6945]), ('37', [3346, 3469, 6815]), ('39', [3305, 3332, 6637]), ('21', [3347, 3148, 6495]), ('43', [2819, 2794, 5613]), ('3', [2726, 2716, 5442]), ('13', [2681, 2661, 5342]), ('59', [2458, 2387, 4845]), ('61', [2426, 2315, 4741]), ('51', [2237, 2222, 4459]), ('55', [2134, 2227, 4361]), ('45', [2174, 2145, 4319]), ('5', [2246, 2035, 4281]), ('49', [2112, 2134, 4246]), ('53', [2004, 2178, 4182]), ('14', [1811, 1925, 3736]), ('15', [1909, 1773, 3682]), ('63', [1869, 1746, 3615]), ('9', [1796, 1674, 3470]), ('7', [1735, 1643, 3378]), ('65', [1702, 1586, 3288]), ('47', [1688, 1594, 3282]), ('18', [1583, 1566, 3149]), ('57', [1480, 1539, 3019]), ('11', [1442, 1461, 2903]), ('6', [1535, 1347, 2882]), ('8', [1307, 1357, 2664]), ('12', [1239, 1409, 2648]), ('1', [1193, 1187, 2380]), ('19', [1100, 1124, 2224]), ('67', [957, 909, 1866]), ('22', [837, 933, 1770]), ('17', [833, 859, 1692]), ('20', [789, 856, 1645]), ('4', [789, 795, 1584]), ('16', [641, 620, 1261]), ('10', [607, 636, 1243]), ('24', [568, 641, 1209]), ('79', [544, 628, 1172]), ('69', [402, 372, 774]), ('2', [295, 373, 668]), ('83', [299, 338, 637]), ('77', [280, 286, 566]), ('85', [262, 294, 556]), ('89', [271, 262, 533]), ('75', [230, 239, 469]), ('91', [207, 216, 423]), ('73', [202, 193, 395]), ('87', [133, 126, 259]), ('71', [117, 133, 250]), ('93', [29, 20, 49])], '地铁7号线': [('23', [4449, 4415, 8864]), ('25', [4364, 4350, 8714]), ('33', [4113, 4145, 8258]), ('29', [3786, 3990, 7776]), ('41', [3856, 3835, 7691]), ('27', [3722, 3920, 7642]), ('31', [3536, 3453, 6989]), ('35', [3477, 3468, 6945]), ('37', [3346, 3469, 6815]), ('39', [3305, 3332, 6637]), ('21', [3347, 3148, 6495]), ('43', [2819, 2794, 5613]), ('3', [2726, 2716, 5442]), ('13', [2681, 2661, 5342]), ('59', [2458, 2387, 4845]), ('61', [2426, 2315, 4741]), ('51', [2237, 2222, 4459]), ('55', [2134, 2227, 4361]), ('45', [2174, 2145, 4319]), ('5', [2246, 2035, 4281]), ('49', [2112, 2134, 4246]), ('53', [2004, 2178, 4182]), ('14', [1811, 1925, 3736]), ('15', [1909, 1773, 3682]), ('63', [1869, 1746, 3615]), ('9', [1796, 1674, 3470]), ('7', [1735, 1643, 3378]), ('65', [1702, 1586, 3288]), ('47', [1688, 1594, 3282]), ('18', [1583, 1566, 3149]), ('57', [1480, 1539, 3019]), ('11', [1442, 1461, 2903]), ('6', [1535, 1347, 2882]), ('8', [1307, 1357, 2664]), ('12', [1239, 1409, 2648]), ('1', [1193, 1187, 2380]), ('19', [1100, 1124, 2224]), ('67', [957, 909, 1866]), ('22', [837, 933, 1770]), ('17', [833, 859, 1692]), ('20', [789, 856, 1645]), ('4', [789, 795, 1584]), ('16', [641, 620, 1261]), ('10', [607, 636, 1243]), ('24', [568, 641, 1209]), ('79', [544, 628, 1172]), ('69', [402, 372, 774]), ('2', [295, 373, 668]), ('83', [299, 338, 637]), ('77', [280, 286, 566]), ('85', [262, 294, 556]), ('89', [271, 262, 533]), ('75', [230, 239, 469]), ('91', [207, 216, 423]), ('73', [202, 193, 395]), ('87', [133, 126, 259]), ('71', [117, 133, 250]), ('93', [29, 20, 49])]}#print(mydic)alllist=[]valuelist=[]for i in mydic.items():valuelist.append(i[1])alllist.append(i)for i in keylist:print(i)for i in valuelist:#print(i)print(i[0],i[1],i[2])print(i[0][1][2])[('23', [4449, 4415, 8864])输出了('23', [4449, 4415, 8864]) ('25', [4364, 4350, 8714]) ('33', [4113, 4145, 8258])8864('23', [4449, 4415, 8864]) ('25', [4364, 4350, 8714]) ('33', [4113, 4145, 8258])8864
- 数据结构与算法_BST树_BST树的定义及删除操作
- Python爬虫实战:抓取京东苹果手机评价
- 浅谈Python发展历史
- 一 Android——数据存储(二十一)
- 1 Python新手入门———条件判断
- 数据让饮食更合理
- access数据库文件的扩展名是什么
- 7.从句学习
- 1万7千多现代诗歌大全ACCESS\EXCEL数据库
- CAD图纸加密软件——公司核心文件数据防泄密「天锐绿盾」