Python Job 1

Source: Internet
Author: User

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

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.