Python day three: mutable types and immutable types, variable assignments, lists, tuples, dictionaries

Source: Internet
Author: User

First, the content

Ii. Exercise 1, Element classification

Requirements: A collection of the following values [11,22,33,44,55,66,77,88,99,90 ...], saving all values greater than 66 to the first key in the dictionary, and saving the value less than 66 to the value of the second key.

That is: {' K1 ': All values greater than 66, ' K2 ': All values less than 66}

L = [11,22,33,44,55,66,77,88,99,90]d = {' K1 ': [], ' K2 ': []}for i in Range (Len (l)):    if l[i] >:        d[' K1 '].append ( L[i])    else:        d[' K2 '].append (L[i]) print (d)

2. Find

Requirements:

Finds elements in a list, removes spaces for each element, and finds all elements that begin with "L" or "L" and End with "K".

Li = ["Dark", "dxxk", "Lisa", "Tony", "SB"]

Tu = ("Dxxk", "Dark", "Lisa", "Tony", "Copila")

DiC = {' K1 ': ' Lisa ', ' K2 ': ' Dark ', ' K3 ': ' Lisa ', ' K4 ': ' Copila '}

3. Output Product List

4. Shopping Cart

5. User interaction, show the choice of three-level linkage between provinces and counties

Python day three: mutable types and immutable types, variable assignments, lists, tuples, dictionaries

Related Article

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.