2017.7.7
来源:互联网 发布:阿里云培训 编辑:程序博客网 时间:2024/05/21 17:10
1.1字典的用法
sarah = []sarahDic = {}sarah = dataHandle2.readDataFromFile('sarah2.txt')sarahDic['Name'] = sarah.pop(0)sarahDic['Dob'] = sarah.pop(0)sarahDic['runtimes'] = sarahprint(sarahDic['Name'] + "'s fatest times are:" + str(sorted(set(dataHandle2.sanitize(t) for t in sarahDic['runtimes']))[0:3]))
字典相较于列表,就是在列表的一些属性上,加上其称号。字典可以随着其加入的值动态扩大
2.关于类的继承
# auth = 'gao'# encoding: utf-8import dataHandle2class AthleteList(list): def __init__(self, a_name, a_dob=None, a_times=[]): list.__init__([]) self.name = a_name self.dob = a_dob self.extend(a_times) def top3(self): return (sorted(set(dataHandle2.sanitize(t) for t in self))[0:3])
继承list的类,拥有list的所有共有方法和属性
3.对类的应用
sarah = dataHandle2.readDataFromFile('sarah2.txt')print(sarah.name + "'s fatest times are:" + str(sarah.top3()))sarah.append('2.09')print(sarah.top3())
所有类的方法都可以被类的实例调用
4.point
5.一个关于python字符串的处理,2和3都能用
6.一个枚举函数enumerate(),返回列表的位置和列表值
animals = ['cat', 'dog', 'monkey']for idx, animal in enumerate(animals): print('#%d: %s' % (idx + 1, animal))# Prints "#1: cat", "#2: dog", "#3: monkey", each on its own line
7.访问字典dict中的键值对:d.item()
d = {'person': 2, 'cat': 4, 'spider': 8}for animal, legs in d.items(): print('A %s has %d legs' % (animal, legs))# Prints "A person has 2 legs", "A cat has 4 legs", "A spider has 8 legs"
今天就到这,吃饭去
阅读全文
0 0
- 2017.7.3--2017.7.7
- 2017.7.7
- 周报2017.7.3-2017.7.7
- 笔记2017.7.7
- 2017.7.7 C组总结
- jzoj P2150【2017.7.7普及】和谐数
- jzoj P2151【2017.7.7普及】分数
- jzoj P2152【2017.7.7普及】终极数
- jzoj P2153【2017.7.7普及】串
- 【集训】jzoj 2017.7.7 noip模拟赛A 总结
- 2017.7.7 机房测试 (模拟,贪心,二分)
- 2017.7.17--2017.7.21
- 2017.7.5(转)python2.7,一个困扰了我一天的print问题
- 我的第一篇博客—IT之路.ZCSDN.2017.7.7
- 2017.7.20
- 2017.7.2
- 2017.7.2
- 2017.7书单
- 进度条ProgressBar样式设计
- 各种网络相关的协议
- Cmake一次编译多个cpp
- JAVA安卓开发在MainActivity之前添加一个含有按钮页面跳转
- HTTP请求报文(请求行、请求头、请求体)
- 2017.7.7
- 博客模版
- quill自定义图片上传
- js实现canvas绘制的图形的拖动效果
- Codeforces Round #202 B:Color the Fence
- 一入侯门深似海,不破楼兰终不回
- 文本四则运算解析工具与浮点数小数精度保留工具
- NIO的基本应用
- 【NOIP2015模拟11.3晚】喝喝喝