Python enumerate reverse index only

前端 未结 10 2225
情深已故
情深已故 2021-02-05 05:43

I am trying to reverse the index given by enumerate whilst retaining the original order of the list being enumerated.

Assume I have the following:



        
10条回答
  •  生来不讨喜
    2021-02-05 06:23

    Python 2

    import itertools
    
    def reversed_enumerate(seq):
        return itertools.izip(reversed(range(len(seq))), reversed(seq))
    

    Python 3

    Substitute zip for itertools.izip :)

提交回复
热议问题