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 ))