Python zip () function transpose table, Action column

Source: Internet
Author: User

>>>zip ([1,2,3],[4,5,6])

[(1,4), (2,5), (4,6)]

The zip () function, where the nth element of each input is paired together, returns a list that contains several tuples. Requirement: The input must be an iterative object (list, tuple, string)

The ZIP (*) transpose all the input object rows to columns.

>>>data=[[1,2,3],[4,5,6]]

>>>zip (*data)

[(1,4), (2,5), (3,6)]

To insert a column at the end of the table

Table=zip (*table)

Table.append ([0,0,0,0])

Table=zip (*table) #zip后每个单元是元素, non-list, must be repeated assignment, the unit list must be converted to a list. Table[1]=list (Table[1])

Python zip () function transpose table, Action column

Related Article

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.