Python3 set, and dictionary, usage tips, python3set

Source: Internet
Author: User

Python3 set, and dictionary, usage tips, python3set


# Set, unordered and repeatable
Setparameters = {'ofgh', 'gegds ', 'utytr '}

Setmetadata. add ('uuuuu ') # add a single element
Setmember. remove ('ofgh') # delete a single element
Print (setexample)
# Duplicate dictionary keys and values
Zidian = {'cn': "chain", 'cn': 'chh '}
Print (len (zidian) # dictionary Length
Print (zidian)
Zidian. _ setitem _ ('us', 'jhu') # Add an element
Print (zidian)
# Set usage
Ry = input ('enter any character :')
Tongji = {}
N = 0
For s in ry:
Tongji. get (s)
If n is None:
Tongji. _ setitem _ (s, 1)
Else:
Tongji. _ setitem _ (s, n + 1)
Print (tongji)
For key in tongji:
Print ('% s appears % d Times' % (key, tongji. get (key )))

# Count after 3
Ct = int (input ('enter an integer :'))
Dui = []

For num in range (1, ct + 1 ):
Dui. append (num)
While True:
If len (dui) = 1:
Break;
N = n + 1
If n % 3 = 0:
Dui. pop (0)
Else:
Dui. append (dui. pop (0 ))
Print (dui)

'''
Functions; independent calls, defined independently
Method: Define the dependency and call the dependency.

'''
# Return the Function
Def huidiao (data, r ):
For a in data:
If r ():
Return

Def guize (B ):
Return B % 3 = 0
Print (huidiao ([1, 2, 3, 4, 5, 6, 7, 8, 9], guize ))

Def daxiao (d, x ):
If d <x:
D, x = x, d
Return d, x
Print (daxiao (1, 6 ))



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.