Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses the zip () function

Shulou Source: shulou.com Published: 2022-06-01 04:26:16 09月13日 Update

This article will explain in detail how python uses the zip () function. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Zip ()

Earlier, when we introduced the map () function, we gave an example of applying a function to two parallel lists, and the zip () function makes it easier to do this.

If we have two lists, the first list contains the first name and the second list contains the last name. Using the zip () function, we can splice them together as follows.

> first_names = ["Peter", "Christian", "Klaus"] > last_names = ["Jensen", "Smith", "Nistrup"] > print (['.join (x) for x in zip (first_names, last_names)]) [' Peter Jensen', 'Christian Smith',' Klaus Nistrup']

In other words, zip turns two equal-length lists into pairs, namely (("Peter", "Jensen"), ("Christian", "Smith"), ("Klaus", "Nistrup")).

This is the end of the article on "how python uses the zip () function". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Tags: Functions two articles more good practical that is that is examples content articles knowledge references help parallel applications related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux MySQL Microsoft OPPO Reno