[Oldboy-django] [5python Basics] [Built-in function]zip

Source: Internet
Author: User
Tags generator

In Python3, two or more two iterators are encapsulated as generators, and tuples are generated continuously in the Loop traversal generator.

If the supplied iterator length is not equal, the length of the generator is the length of the shortest iterator.

#coding= Utf-8#Zip multiple iterative objects run at the same time, then the respective values are combined together#The length of the wrong conditionL1 = [1, 2, 3]l2='ABCD'Z=Zip (L1, L2)Print(list (z))#output [(1, ' a '), (2, ' B '), (3, ' C ')]#length equivalenceL1 = [1, 2, 3]l2='CCD'Z=Zip (L1, L2)Print(list (z))#output [(1, ' C '), (2, ' C '), (3, ' d ')]#Variable zip generatorname = ['Celia','Lisa','Marie']len_name= [Len (n) forNinchName] forName, Len_nameinchZip (name, len_name):Print(Name, Len_name)
View Code

[Oldboy-django] [5python Basics] [Built-in function]zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.