Job 1: Combining nesting
Like the following list, each function is implemented as required
list = [[' K ', [' qwe ', 20,{' K1 ': [' TT ', 3, ' 1 ']},89], ' AB ']
Turn TT into uppercase, in two ways
Converts the number 3 to the string ' 100 ', implemented in two ways
Convert the string ' 1 ' to the number 101, implemented in two ways
Idea
Take the serial number of the TT directly, then replace; Find TT, then capitalize;
Also, note that strings are quoted, numbers are not quoted, and TT and TT are replaced
list = [[' K ', [' qwe ', 20,{' K1 ': [' TT ', 3, ' 1 ']},89], ' AB ']
Q1 = list[0][1][2].get (' K1 ')
Q1[0] = Q1[0].upper () #方法1, directly locate the ordinal and replace with uppercase
list[0][1][2][' k1 '] = Q1
Print ("TT Change TT:")
Print ("Method 1 Result:")
Print (list)
list = [[' K ', [' qwe ', 20,{' K1 ': [' TT ', 3, ' 1 ']},89], ' AB ']
Print ("Re-assignment:")
Print (list)
D1 = list[0][1][2]
For key in D1: #方法2, traverse Dictionary jian, if it is ' TT ', remove and then insert ' TT '
If ' TT ' in D1[key]:
D1[key].insert (D1[key].index (' TT '), ' TT ')
D1[key].remove (' TT ')
Print ("Method 2 Result:")
Print (list)
Python Job 1