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: