i have just started using python and i can't figure out what is meant by parallel list any info would be great . i think it is just using two list to store info
"Parallel lists" is a variation on the term "parallel array". The idea is that instead of having a single array/list/collection of records (objects with attributes, in Python terminology) you have a separate array/list/collection for each field of a conceptual record.
For example, you could have Person records with a name, age, and occupation:
people = [
Person(name='Bob', age=38, occupation=PROFESSIONAL_WEASEL_TRAINER),
Person(name='Douglas', age=42, occupation=WRITER),
# etc.
]
or you could have "parallel lists" for each attribute:
names = ['Bob', 'Douglas', ...]
ages = [38, 42, ...]
occupations = [PROFESSIONAL_WEASEL_TRAINER, WRITER, ...]
Both of these approaches store the same information, but depending on what you're doing one may be more efficient to deal with than the other. Using a parallel collection can also be handy if you want to sort of "annotate" a given collection without actually modifying the original.
(Parallel arrays were also really common in languages that didn't support proper records but which did support arrays, like many versions of BASIC for 8-bit machines.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With