An example analysis of integer manipulation and character manipulation and matrix manipulation in Python about list lists

Source: Internet
Author: User
Tags python list
This article mainly introduces the Python list parsing operation, combined with instance form to analyze the Python list for integer, character and matrix parsing operation implementation skills, the need for friends can refer to the following

The example in this article describes the list parsing operation for Python lists. Share to everyone for your reference, as follows:


#coding =utf8print ' "Python uses a For loop in a row to place all values in a single list. The syntax for list parsing is as follows: [Expr for Iter_var in iterable][expr for Iter_var in iterable if COND_EXPR]----------------------------------- ------------------------------' print ' adds five to the number 0 to 8, and puts the result value in the Linlist "intlist=[x+5 for x in range (8)]for ele in Intlist : Print Ele,printprint "picks up the odd number from 0 to 8 and powers it, and the result is saved at Powerlist" Powerlist=[x **2 for X in range (8) if X%2]for Pl in Powerli St:print Pl,printprint "Converts the string Ewang to uppercase and saves the result in Upperlist" Upperlist=[char.upper () for char in "Ewang"]for up in Upperl Ist:print up,printprint "" Converts the uppercase letters in the string Ewaang to lowercase, and records the value of the corresponding index. Save the letters and index values that need to be converted to matrixlist ' str= ' Ewaang ' matrixlist=[(Char.lower (), index) for char in STR if char.isupper () for index in Range (len (str)) if Str[index].isupper () and Str[index]==char]for mat in Matrixlist:print mat,print

Operation Result:

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.