反向枚举
renumerate的Python项目详细描述
雷诺数
反向枚举。
概述
renumerate(序列,开始=长度(序列)-1,结束=0):
Return an enumerate object.sequence must be an object that has a __reversed__() method or supports thesequence protocol (the __len__() method and the __getitem__() method withinteger arguments starting at 0).The __next__() method of the iterator returned by renumerate() returns a tuplecontaining a count (from start which defaults to len(sequence) - 1 or ends atend which defaults to 0 - but not both) and the values obtained from reverseiterating over sequence.
>>>fromrenumerateimportrenumerate>>>seasons=['Spring','Summer','Fall','Winter']>>>list(renumerate(seasons))[(3,'Winter'),(2,'Fall'),(1,'Summer'),(0,'Spring')]>>>list(renumerate(seasons,start=4))[(4,'Winter'),(3,'Fall'),(2,'Summer'),(1,'Spring')]>>>list(renumerate(seasons,end=2))[(5,'Winter'),(4,'Fall'),(3,'Summer'),(2,'Spring')]
相当于:
defrenumerate(sequence,start=None,end=None):ifstartisnotNoneandendisnotNone:raiseTypeError("renumerate() only accepts start argument or end argument"" - not both.")ifstartisNone:start=len(sequence)-1ifendisNone:end=0n=start+endforeleminreversed(sequence):yieldn,elemn-=1
安装
先决条件:
- python 2.7或python 3.4或更高版本
- http://www.python.org/
- 2.7和3.7是主要的测试环境。
- pip和setuptools
要安装,请运行:
python -m pip install --upgrade renumerate
开发
从源安装:
克隆sources并运行:
python -m pip install ./renumerate
或开发模式:
python -m pip install --editable ./renumerate
先决条件:
开发严格基于tox。要安装它,请运行:
python -m pip install tox
许可证
Copyright (c) 2016-2019 Adam KarpierzLicensed under the zlib/libpng LicensePlease refer to the accompanying LICENSE file.
更改日志
1.0.9(2019-05-22)
- 放弃对python 2的支持。
1.0.8(2019-05-21)
- 更新所需的setuptools版本。
- 安装更新和改进。
- 这是支持python 2的最新版本。
1.0.7(2018-11-08)
- 放弃对Python2.6和3.0-3.3的支持
- 更新所需的setuptools版本。
1.0.6(2018-05-08)
- 修复描述中的错误。
- 更新所需的setuptools版本。
- 改进和简化安装和打包。
1.0.5(2018-02-26)
- 改进和简化安装和打包。
1.0.4(2018-01-28)
- 修复tox.ini中的错误和不一致性
- 更新readme.rst。
1.0.1(2018-01-24)
- 更新所需的sphinx版本。
- 更新doc sphinx配置文件。
1.0.0(2017-11-18)
- 安装改进。
- 其他小改进。
1.0.0b1(2017-11-18)
- 小改进。
0.3.4(2017-01-05)
- 小的安装改进。
0.3.3(2016-09-25)
- 修复setup.py中的错误
0.3.1(2016-09-25)
- 更符合PEP8
0.2.2(2016-09-24)
- 描述元素
- 小修小修。
0.1.1(2016-09-24)
- 第一个有用的版本。
0.0.2(2016-09-23)
- 初次发布。