[Tutor] double ended queue
Steven D'Aprano
steve at pearwood.info
Sat Nov 4 20:26:38 EDT 2017
On Sat, Nov 04, 2017 at 10:11:08PM +0200, Atux Atux wrote:
[...]
> i got the starting point where it asks the user and goes until 'q' is
> pressed.
>
> while True:
> if input("\n\n\nType a number to add it to the queue or q to
> exit: ") == 'q':
> break
>
> but i a stuck on how to continue asking and adding to the list
To start with, you have to actually have a list to add to.
queue = []
To add to the left of the queue, use:
queue.insert(0, value)
To add to the right of the queue, use:
queue.append(value)
To delete the first value:
del queue[0]
and to delete the last:
del queue[len(queue)-1]
--
Steve
More information about the Tutor
mailing list