Python数据结构索引从1开始,而不是0? [英] Python Data structure index Start at 1 instead of 0?

查看:250
本文介绍了Python数据结构索引从1开始,而不是0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:我有64个数字的列表永远不会改变:

 (2,4, 6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,54, 56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104, 106,108,110,112,114,116,118,120,122,124,126,128)



我需要一个Python中的数据结构,这样我就可以使用1-64索引来取代这些数字,而不是标准的0-63。这可能吗?最好的方法是建立一个字典?

解决方案

只需插入一个 0 在结构的开头:

 (0,2,4,6,8,... )


I have a weird question: I have this list of 64 numbers that will never change:

(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128)

I need a data structure in Python that will allow me to accsess these numbers using a 1-64 index as opposed to the standard 0-63. Is this possible? Would the best way to accomplish this be to build a dictionary?

解决方案

Just insert a 0 at the beginning of the structure:

(0, 2, 4, 6, 8, ...)

这篇关于Python数据结构索引从1开始,而不是0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆