Search code examples
pythondeque

Best way to convert deque values to an index list?


I have a deque filled with datetime.datetime's and need to convert the values to the deque's index in order to handle the deque in numpy. Is there a function similar to index.tolist() which is used in pandas that's used for handling a deque? Or maybe a more efficient way of getting the index values without creating a list?

Desired input/output:

Input >>> deque(2018-12-19 09:26:03.478039, 2018-12-20 09:26:03.478039, 2018-12-21 09:26:03.478039, 2018-12-22 09:26:03.478039, 2018-12-23 09:26:03.478039)

Output >>> (0, 1, 2, 3, 4)

Solution

  • This is simply:

    range(len(your_deque))