Lecture 42: Implementation method of Python parallel loop traversal sequence

There are many requirements to traverse multiple iterable objects at the same time, and multiple iterable elements are matched with each other to form specific functions, which is parallel loop traversal.

For example, there is such a requirement: the user's name, age, and profession need to be printed out.

The user's name, age, profession are all stored in separate lists.

When realizing such a requirement, it is necessary to ensure that the data in each list is in one-to-one correspondence, that is to say, the indexes of the three data of name, age, and major must be guaranteed to be the same, otherwise the data will be confused.

Method 1: Use indexes to traverse in parallel

The index numbers of the three data of name, age, and major are the same, that is to say, elements with the same index in the list will form a piece of data. Since elements with the same index can form a piece of data, then we can traverse according to the index number .

user = ['jiangxl', 'wangwu', 'zhangsan'

Guess you like

Origin blog.csdn.net/weixin_44953658/article/details/130615903