Python enumerate reverse index only

前端 未结 10 2234
情深已故
情深已故 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:35

    I don't know if this solution is better for you, but at least it's shorter:

    >>> [(4 - x, x) for x in range(5)]
    [(4, 0), (3, 1), (2, 2), (1, 3), (0, 4)]
    

提交回复
热议问题