Returns the element at index after moving it to the beginning of the queue. >>> x = [1, 2, 3, 4] >>> requeue(x) 4 >>> x [4, 1, 2, 3]
(queue, index=-1)
| 830 | |
| 831 | |
| 832 | def requeue(queue, index=-1): |
| 833 | """Returns the element at index after moving it to the beginning of the queue. |
| 834 | |
| 835 | >>> x = [1, 2, 3, 4] |
| 836 | >>> requeue(x) |
| 837 | 4 |
| 838 | >>> x |
| 839 | [4, 1, 2, 3] |
| 840 | """ |
| 841 | x = queue.pop(index) |
| 842 | queue.insert(0, x) |
| 843 | return x |
| 844 | |
| 845 | |
| 846 | def restack(stack, index=0): |