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.