insertion order
The order in which items were added to a collection, which Python dicts preserve when you iterate over them.
In more detail
Iterating over a dict yields keys in the order they were first inserted; this has been part of the language since Python 3.7. Updating an existing key keeps its position, while deleting and re-adding moves it to the end. Sets make no such promise, so their iteration order should never be relied on.
Related terms
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
- set — Python's built-in unordered collection of unique items, implemented as a hash table that stores keys without values.
- stable sort — A sort that keeps items with equal keys in the same relative order they had before sorting.
Taught in
- Python Dicts And Sets Under The Hood — Algorithms & Data Structures for Working Engineers
- Choosing The Right Sequence — Algorithms & Data Structures for Working Engineers
- Binary Trees And Their Traversals — Algorithms & Data Structures for Working Engineers
- Binary Search Trees: Search, Insert And Delete — Algorithms & Data Structures for Working Engineers
- AVL Trees: Rotations That Keep The Guarantee — Algorithms & Data Structures for Working Engineers
- Dijkstra: Shortest Paths With A Priority Queue — Algorithms & Data Structures for Working Engineers