40 likes | 88 Views
Lists in Python. Parallel lists. Parallel lists. This is a technique for using lists which goes back to the early days of programming It’s not new syntax, just a slightly different way to look at arrays
E N D
Lists in Python Parallel lists
Parallel lists • This is a technique for using lists which goes back to the early days of programming • It’s not new syntax, just a slightly different way to look at arrays • Many languages have a restriction that an array can be only one type, an integer array, a string array, etc.
Sometimes the situation required storing both floats and strings, for example (GPAs and names). • One piece of data, a GPA, belongs with another piece of data, a name. • Since they could not be put in the same array, they were put in separate arrays, but in the same position.
Parallel arrays • By using the same subscript for both arrays, you are referring to related data. • The main thing to remember is if you move data around in one of the arrays, you must make the same moves in the other array • Nothing in the language enforces this relationship, it’s up to your programming