make array index 1 instead of index 0 based

Viewed 20992

How can I make an array start at subscript 1 instead of subscript 0 in python?

Basically to solve this problem in python.

4 Answers

You can use custom indexes of the fidx module:

import fidx

# create custom type `list1b` from `list`
fidx.add(list, name='list1b')

# add a map for int indexes (i -> i-1)
fidx.list1b.set_index_map(int, lambda _,i: i-1, override=True)

# create your list
b = fidx.list1b([1,2,3])

print(b[1], b[2], b[3]) # (1, 2, 3)
Related