this post was submitted on 04 Oct 2023
10 points (100.0% liked)

Python

6416 readers
4 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] -2 points 1 year ago (2 children)

When you need a doubly-linked list in Python, you can use the deque data structure, which is in the collections module

When do I need a doubly-linked list in Python? Whenever I have something where I can often expect to interact with the first and last element of it? Always, because it's more efficient than shifting the entire list around? Something else entirely?

[โ€“] wosat 5 points 1 year ago

You can use a deque as a stack (First In, Last Out) or as a queue (First In, First Out). Lists are especially inefficient when adding/removing from the beginning of the list, but, for deques, it's a O(1) operation.

load more comments (1 replies)