queue represented by a python list from collections abc import iterable from typing import generic typevar t typevart class queuebylistgenerict def initself iterable iterablet none none none self entries listt listiterable or def lenself int return lenself entries def reprself str return fqueuetupleself entries def putself item t none self entries appenditem def getself t if not self entries raise indexerrorqueue is empty return self entries pop0 def rotateself rotation int none put self entries append get self entries pop for in rangerotation putget0 def getfrontself t return self entries0 if name main from doctest import testmod testmod queuebylist queue queuebylist 10 20 30 queue 10 20 30 queuebylist i 2 for i in range 1 4 queue 1 4 9 len queuebylist 0 from string import ascii_lowercase len queuebylist ascii_lowercase 26 queue queuebylist for i in range 1 11 queue put i len queue 10 for i in range 2 queue get 1 2 len queue 8 queue queuebylist queue queue str queue queue queue put 10 queue queue 10 queue put 20 queue put 30 queue queue 10 20 30 put item to the queue queue queuebylist queue put 10 queue put 20 len queue 2 queue queue 10 20 get item from the queue queue queuebylist 10 20 30 queue get 10 queue put 40 queue get 20 queue get 30 len queue 1 queue get 40 queue get traceback most recent call last indexerror queue is empty rotate the items of the queue rotation times queue queuebylist 10 20 30 40 queue queue 10 20 30 40 queue rotate 1 queue queue 20 30 40 10 queue rotate 2 queue queue 40 10 20 30 get the front item from the queue queue queuebylist 10 20 30 queue get_front 10 queue queue 10 20 30 queue get 10 queue get_front 20
from collections.abc import Iterable
from typing import Generic, TypeVar

_T = TypeVar("_T")


class QueueByList(Generic[_T]):
    def __init__(self, iterable: Iterable[_T] | None = None) -> None:
        
        self.entries: list[_T] = list(iterable or [])

    def __len__(self) -> int:
        

        return len(self.entries)

    def __repr__(self) -> str:
        

        return f"Queue({tuple(self.entries)})"

    def put(self, item: _T) -> None:
        

        self.entries.append(item)

    def get(self) -> _T:
        

        if not self.entries:
            raise IndexError("Queue is empty")
        return self.entries.pop(0)

    def rotate(self, rotation: int) -> None:
        

        put = self.entries.append
        get = self.entries.pop

        for _ in range(rotation):
            put(get(0))

    def get_front(self) -> _T:
        

        return self.entries[0]


if __name__ == "__main__":
    from doctest import testmod

    testmod()