Python Data structure exercises

Source: Internet
Author: User

1. Given the list L, such as [2,5,3,8,10,1], sort it in ascending order and output.

Code: list = [2,5,8,10,1]
Print (list)
List.sort ()
Print (list)

2. Given a string s, such as ' 123456 ', reverse it out, using slices

Code: str = ' 123456 '

Print (Str[::-1])

3. Given the dictionary dict, such as {' A ': 1, ' B ': ' 2 ', ' C ': ' 3 '}, output its key and value, respectively. Insert the dictionary {' d ': 4} into it and output the new Zid

Code:

Dict = {"A": "1", "B": "2", "C": "3"}
Print (Dict.keys ())
Print (Dict.values ())
Dict.setdefault ("D")
dict["D"] = "4"
Print (DICT)

4. Find out all primes within 100

Range (2,101):
0
Range (2, (i-1)):
0):
1
0):
Print (i)

Python Data structure exercises

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.