If we've decided to create a collection that uses an item's position—a list
—we have several ways of building this structure. We'll look at a number of ways we can build a list object from individual items.
In some cases, we'll need a list because it allows duplicate values. A great many statistical operations don't require knowing the position of an item. A multiset would be useful for this, but we don't have this as a built-in structure; it's very common to use a list
instead of a multiset.
Let's say we need to do some statistical analyses on some file sizes. Here's a short script that will provide us with the sizes of some files:
>>> import pathlib
>>> home = pathlib.Path('source')
>>> for path in home.glob('*/index.rst'):
... print(path.stat().st_size, path.parent)
2353 source/ch_01_numbers_strings_and_tuples
2889 source/ch_02_statements_and_syntax
2195 source/ch_03_functions
3094...