python 字典小结

字典分为键和值,具体看例程:

>>> dict = {'Name': 'Zara', 'Age': 7}
>>> print(dict.values)

>>> print(dict.values())
dict_values(['Zara', 7])
>>> print()
>>> print(dict.keys())
dict_keys(['Name', 'Age'])

>>> a=list(dict.keys())
>>> b=list(dict.values())
>>> print(a)
['Name', 'Age']
>>> print(b)
['Zara', 7]

>>> for i,j in dict.items():
...    if i=='Age':
...        print(j)
... 
7

>>> for k,v in dict.items():
...   print(k,v,end='\n')
... 
Name Zara
Age 7

两个字典键值一样,合成新的字典


ListA['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
ListB=['.-','...','-.-','-..','.','..-','--.','....','..','.----','-.-','.-..','--','-.','---',  '.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..']
mydicti = dict(zip(ListA,ListB))
print(mydicti)

 

你可能感兴趣的:(python)