This is one idea for thread of some lessons learned with experience about asking wrong question and answers 'thinking out of box'. If there is need to have sticky, I suggest that this thread become sticky development thread and moderator can move the upvoted suggestions for next part in new sticky thread established.

Please express if you think there is need or not.

Here is one first sample of questions I consider to make suggestion more concrete.

PYTHON Frequently misasked questions

Q1:

Wrong question 1)
I need linked list, how should I make one?

Correct question 1)
I need to make list which changes a lot, which data structure should I use?

Correct answer 1)
There is super fine and fast implementation of alternative list structure originally offered as replacement of current one. However the performance charasterics change was considered undesirable and so you must download it as separate module blist. In addition to blist type it offers also other data structures:

  • sortedlist
  • sortedset
  • weaksortedlist
  • weaksorteset
  • sorteddict
  • btuple

It is in pypi and you can download and install it with easy_install blist from setuptools
or pip install blist if you have installed pip advanced installation tool.

Dani AI

Generated

Asking “How do I make a linked list?” is the classic misask. The right question is “Which operations will be hotspots (indexing, push/pop at either end, many middle inserts/removals, or keeping items sorted)?” — pick the container to match the operations, not the name of a data structure. CPython’s built-in list is a variable-length array (fast random access; costly inserts/removals away from the end). (docs.python.org)

For many use-cases that prompt people to ask for a linked list, a built-in solution already fits. Use list for random-access-heavy code and moderate changes. Use collections.deque when you need efficient append/pop from either end (O(1) amortized) — it’s the standard “linked-list-like” choice in CPython for queue/stack patterns. A minimal example:

from collections import deque

dq = deque([1, 2, 3])
dq.appendleft(0)   # cheap
dq.append(4)       # cheap
dq.popleft()       # cheap

Prefer deque over list.pop(0) or list.insert(0, x) when you frequently touch the left end. (docs.python.org)

When you need sorted sequences or lots of middle insertions while keeping order, consider a purpose-built third‑party container rather than hand-rolling nodes. sortedcontainers (SortedList/SortedDict) is a well-maintained, high-performance pure‑Python option; real node-based linked-list extensions such as llist exist if you truly need node semantics and O(1) splice-like operations. Also note ’s mention of other third‑party options — those are worth exploring, but benchmark first. (pypi.org)

Practical rule: measure before redesigning. Big‑O gives direction but constants and memory layout matter; use timeit and a profiler to test realistic workloads and data sizes before replacing built-ins. If middle inserts are the hotspot, profile to confirm, then pick a specialized container. (docs.python.org)

Looks like there is no interest, so I close the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.