In Python, there is no need to loop through two arrays at the same time and process the corresponding elements and delete them

For the Python language, if you don't use loops when writing code, try not to use loops. Some functions built into the language tend to be more efficient.

Let's take an example to illustrate: For example, we have two lists of the same size, and we need to judge the corresponding elements of the two lists at the same time, and delete the ones that meet the requirements.

In Python, there is no need to loop through two arrays at the same time and process the corresponding elements and delete them

  1. x, yare two lists, the above example will delete xthe ycorresponding elements.
  2. The inner ones zipwill pack, and the outer ones xwill unpack the processed elements. Note: External function unpacking requires adding numbers to variables.yzipzip*
  3. Notice that the processed data becomes a tuple.

Is it very simple, there is no loop, but the data is traversed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325694001&siteId=291194637