3 ms·
What do a-list/p-list have to do with sharing structure? If you want shared structure of lists in Python, use `itertools.chain`. If you want key-value mapping
by o11c 3y ago
What do a-list/p-list have to do with sharing structure?
If you want shared structure of lists in Python, use `itertools.chain`.
If you want key-value mappings, use a dict. Order is preserved by default nowadays, and conversion to/from an iterable of 2-tuples is trivial.
- thaumasiotes 3y ago> If you want shared structure of lists in Python, use `itertools.chain`. That would involve zero shared structure. itertools.chain is just an iterator that iterates one iterable and then, instead of declaring that it's done, goes on to iterate another one. Shared structure between lists means that two lists refer to some of the same regions of memory.
- o11c 3y agoAnd multiple `itertools.chain` instances pointing to the same list chunk(s) also use sharing.
- thaumasiotes 3y agoOK, that is true, but that approach would have the significant downside that you can't pass over a list more than once.