“数组索引应该从0开始还是从1开始?我对0.5的妥协被拒绝了。
bootle的Python项目详细描述
bootle:python的半索引列表
“数组索引应该从0开始还是从1开始?我0.5的妥协被拒绝了 没有,我想,适当的考虑。”——斯坦·凯利·布特尔
安装
pip3 install bootle
用法
frombootleimportListxs=List([1,2,3])assertxs[0.5]==1assertxs[:1.5]==[1]xs[1.5]==2assertxs.index(2)==1.5
参考文献
- "Why numbering should start at zero",埃德格w.迪克斯特拉,1982年
- Why Numbering Should Start At Zero,维基百科
- Why Numbering Should Start At One,维基百科
- Zero-based numbering,维基百科
许可证
wtfpl