__repr__等内置函数==实现使用列表实现循环数据结构
来源:互联网 发布:任意号码显示软件 编辑:程序博客网 时间:2024/06/05 18:38
#coding=utf-8__author__ = 'mac'class Ring(object): def __init__(self,l): if not len(l): raise "ring must have at least one element" self._data=l #__repr__打印,以list打印 def __repr__(self): return repr(self._data) def __len__(self): return len(self._data) def __getitem__(self, i): return self._data[i] def turn(self): last=self._data.pop(-1) self._data.insert(0,last) def first(self): return self._data[0] def last(self): return self._data[-1]l=[{1:1},{2:2},{3:3}]c=Ring(l)print cprint c.first()print c.last()c.turn()print cc.turn()print cclass Fib(object): def __getitem__(self, n): if isinstance(n,int): a,b=1,1 for x in range(n): a,b=b,a+b return a if isinstance(n,slice): start=n.start stop=n.stop a,b=1,1 L=[] for x in range(stop): if x >=start: L.append(a) a,b=b,a+b return Lf=Fib()print f[0:5]
阅读全文
0 0
- __repr__等内置函数==实现使用列表实现循环数据结构
- 不使用for、while等循环实现strlen()函数
- 可变参数函数printf的实现(不使用va_list等内置宏定义)
- 数据结构实现循环双链表
- 数据结构-列表实现
- 数据结构:JavaScript实现列表
- 实现Python列表字典循环
- 【Python-3.3】使用while循环实现列表间数据移动
- 剑指offer---不使用循环条件判断等实现求和
- 使用php重新实现PHP脚本引擎内置函数
- 使用 SQL 内置函数实现对段的加密
- 使用php重新实现PHP脚本引擎内置函数
- 使用php重新实现PHP脚本引擎内置函数
- 使用PHP内置的DES算法函数实现数据…
- spark实现uv统计(使用内置函数)
- 不使用内置函数实现sterev (php)
- PHP内置字符串函数实现
- PHP内置字符串函数实现
- js 九九乘法表
- Delphi预编译指令总结
- 从网络上请求数据,在本地List View配置
- 平稳时间序列参数估计
- android 修改videoview的宽度和高度
- __repr__等内置函数==实现使用列表实现循环数据结构
- URL编码转换函数:escape()、encodeURI()、encodeURIComponent()
- Desktoppr与 Dropbox国内成功使用
- 压栈思想计算Java运算表达式
- Delphi常用系统函数总结
- 【代码笔记】iOS-产生随机字符串
- ftp与sftp文件上传工具类
- QT5学习
- #730 – 使用QueryContinueDrag 事件(Use QueryContinueDrag Event to Know When Mouse Button State Changes)