How to enumerate a range of numbers starting at 1

后端 未结 12 1138
谎友^
谎友^ 2020-11-29 23:42

I am using Python 2.5, I want an enumeration like so (starting at 1 instead of 0):

[(1, 2000), (2, 2001), (3, 2002), (4, 2003), (5, 2004)]

12条回答
  •  一向
    一向 (楼主)
    2020-11-30 00:04

    I don't know how these posts could possibly be made more complicated then the following:

    # Just pass the start argument to enumerate ...
    for i,word in enumerate(allWords, 1):
        word2idx[word]=i
        idx2word[i]=word
    

提交回复
热议问题