Python list parsing operation example [Integer Operation, character operation, matrix operation], pythonlist

Source: Internet
Author: User
Tags iterable python list

Python list parsing operation example [Integer Operation, character operation, matrix operation], pythonlist

This example describes the Python list parsing operation. We will share this with you for your reference. The details are as follows:

# Coding = utf8print ''' Python uses a for Loop in a row to put all values in a list. The syntax for list Parsing is as follows: [expr for iter_var in iterable] [expr for iter_var in iterable if cond_expr] Comment ''' print "adds the numbers 0 to 8 to five in sequence, and put the result value in linList. "intList = [x + 5 for x in range (8)] for ele in intList: print ele, printprint "pick out odd numbers from 0 to 8, and perform the multiplication operation on odd numbers. The result is saved in powerLIst" powerList = [x ** 2 for x in range (8) if x % 2] for pl in powerList: print pl, printprint "converts the string ewang into uppercase letters. And save the result in upperList. "upperList = [char. upper () for char in "ewang"] for up in upperList: print up, printprint ''' converts uppercase letters in the string EwAaNg to lowercase letters, and record the value of the corresponding index. Save the letters and index values to be converted in 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

Running result:

For more Python-related content, refer to this topic: Python list) operation Skills summary, Python coding skills summary, Python data structure and algorithm tutorial, Python function usage skills summary, Python string operation skills summary, Python basic and advanced tutorial and Python file and directory operation tips

I hope this article will help you with Python programming.

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.