Python数据结构索引从1开始,而不是0?

编程入门 行业动态 更新时间:2024-10-16 02:29:18
本文介绍了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?

本文发布于:2023-11-30 02:06:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据结构   而不是   索引   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!