Skip to content

Commit

Permalink
docs/library/collections: Update deque docs to describe new features.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Mar 18, 2024
1 parent c9016b4 commit d92dff8
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions docs/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,47 @@ Classes
appends and pops from either side of the deque. New deques are created
using the following arguments:

- *iterable* must be the empty tuple, and the new deque is created empty.
- *iterable* is an iterable used to populate the deque when it is
created. It can be an empty tuple or list to create a deque that
is initially empty.

- *maxlen* must be specified and the deque will be bounded to this
maximum length. Once the deque is full, any new items added will
discard items from the opposite end.

- The optional *flags* can be 1 to check for overflow when adding items.

As well as supporting `bool` and `len`, deque objects have the following
methods:
Deque objects support `bool`, `len`, iteration and subscript load and store.
They also have the following methods:

.. method:: deque.append(x)

Add *x* to the right side of the deque.
Raises IndexError if overflow checking is enabled and there is no more room left.
Raises ``IndexError`` if overflow checking is enabled and there is
no more room in the queue.

.. method:: deque.appendleft(x)

Add *x* to the left side of the deque.
Raises ``IndexError`` if overflow checking is enabled and there is
no more room in the queue.

.. method:: deque.pop()

Remove and return an item from the right side of the deque.
Raises ``IndexError`` if no items are present.

.. method:: deque.popleft()

Remove and return an item from the left side of the deque.
Raises IndexError if no items are present.
Raises ``IndexError`` if no items are present.

.. method:: deque.extend(iterable)

Extend the deque by appending all the items from *iterable* to
the right of the deque.
Raises ``IndexError`` if overflow checking is enabled and there is
no more room in the deque.

.. function:: namedtuple(name, fields)

Expand Down

0 comments on commit d92dff8

Please sign in to comment.