标签:false bsp dex col 统计 div logs 字符 实例
实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。
例如,查询第一个3分的下标
统计1分的同学有多少个,3分的同学有多少个
>>> a=list(‘1123231132213‘) >>> a [‘1‘, ‘1‘, ‘2‘, ‘3‘, ‘2‘, ‘3‘, ‘1‘, ‘1‘, ‘3‘, ‘2‘, ‘2‘, ‘1‘, ‘3‘] >>> a[3]=‘4‘ >>> a [‘1‘, ‘1‘, ‘2‘, ‘4‘, ‘2‘, ‘3‘, ‘1‘, ‘1‘, ‘3‘, ‘2‘, ‘2‘, ‘1‘, ‘3‘] >>> a.index(‘3‘) 5 >>> a.append(‘5‘) >>> a [‘1‘, ‘1‘, ‘2‘, ‘4‘, ‘2‘, ‘3‘, ‘1‘, ‘1‘, ‘3‘, ‘2‘, ‘2‘, ‘1‘, ‘3‘, ‘5‘] >>> a.pop(-3) ‘1‘ >>> a [‘1‘, ‘1‘, ‘2‘, ‘4‘, ‘2‘, ‘3‘, ‘1‘, ‘1‘, ‘3‘, ‘2‘, ‘2‘, ‘3‘, ‘5‘] >>> len(a) 13 >>> a.insert(1,‘hello‘) >>> a [‘1‘, ‘hello‘, ‘1‘, ‘2‘, ‘4‘, ‘2‘, ‘3‘, ‘1‘, ‘1‘, ‘3‘, ‘2‘, ‘2‘, ‘3‘, ‘5‘]
>>> d={‘09‘:‘66‘,‘05‘:‘80‘,‘14‘:‘78‘,‘23‘:‘90‘} >>> d[‘14‘] ‘78‘ >>> d.keys() dict_keys([‘09‘, ‘05‘, ‘14‘, ‘23‘]) >>> d.values() dict_values([‘66‘, ‘80‘, ‘78‘, ‘90‘]) >>> d.items() dict_items([(‘09‘, ‘66‘), (‘05‘, ‘80‘), (‘14‘, ‘78‘), (‘23‘, ‘90‘)]) >>> d.get(‘05‘,‘66‘) ‘80‘ >>> d.pop(‘23‘,‘80‘) ‘90‘ >>> d {‘09‘: ‘66‘, ‘05‘: ‘80‘, ‘14‘: ‘78‘} >>> ‘04‘ in d False >>> ‘05‘in d True >>> del(d[‘09‘]) >>> d {‘05‘: ‘80‘, ‘14‘: ‘78‘}
>>> d["02"]="90"
>>> d
{‘05‘: ‘80‘, ‘14‘: ‘78‘, ‘02‘: ‘90‘}
标签:false bsp dex col 统计 div logs 字符 实例
原文地址:http://www.cnblogs.com/millmill/p/7559762.html