Feature proposal: mixing 0-based and 1-based indices with `a[i]` and `a{i}`

You could do something like

  • The class is a normal list
  • But it has an extra attribute called o or one that shifts the list into 1-indexing mode. So
mylist = ZeroOrOneList(['a', 'b', 'c'])
mylist[0]
# 1
mylist.o[1]
# 1

So [...] gives you zero indexing, .o[...] gives you one indexing. I think such a class could be written and achieve what the OP is asking for, just replacing the OPs syntax of {...} with .o[...].

5 Likes