
Notes on CPython Lists - rusbus
https://rcoh.svbtle.com/notes-of-cpython-lists
======
fernly
Hmm. You mention having

> ...Another reason to preallocate Python lists when possible.

But how would one do that? I mean, you could do `list(range(10000))` which
would in a sense pre-allocate a 10000-element list. But, does the `list()`
operation look ahead and make a list that size at once, or does it just keep
appending the next item from the iterable, going through the 12% expansions
multiple times?

Also, I can't think offhand of an iterable that would generate N identical
"empty" list items. Like 10000 zeros or 10000 Nones. Anyone?

------
est
> Creating List slices ... with some sort of copy-on-write semantics

[https://docs.python.org/3/library/stdtypes.html#memoryview](https://docs.python.org/3/library/stdtypes.html#memoryview)

