>>> dic = {'one':1,'two':2,'three':3,'four':4,'five':5}
>>> dic
{'four': 4, 'three': 3, 'five': 5, 'two': 2, 'one': 1}
>>> dic['six'] = 6
>>> dic
{'six': 6, 'three': 3, 'two': 2, 'four': 4, 'five': 5, 'one': 1}
>>> del dic['five']
>>> dic
{'six': 6, 'three': 3, 'two': 2, 'four': 4, 'one': 1}
>>> dic['seven'] = 7
>>> dic
{'seven': 7, 'six': 6, 'three': 3, 'two': 2, 'four': 4, 'one': 1}
>>> dic.key()
Traceback (most recent call last):
File "
AttributeError: 'dict' object has no attribute 'key'
>>> dic.keys()
['seven', 'six', 'three', 'two', 'four', 'one']
>>> dic['seven']
7
>>> dic['one']
1
>>> 'one' in dic
True
>>> 'three' in dic
True
>>> 'kjkk' in dic
False
>>> del dic['one']
>>> dic
{'seven': 7, 'six': 6, 'three': 3, 'two': 2, 'four': 4}
>>> dic.keys()
['seven', 'six', 'three', 'two', 'four']
>>> dic.values()
[7, 6, 3, 2, 4]
>>> a=[('aass',23),('iiii',56),('dftj',38)]
>>> a
[('aass', 23), ('iiii', 56), ('dftj', 38)]
>>> dict(a)
{'aass': 23, 'iiii': 56, 'dftj': 38}
>>> b = dict(a)
>>> b
{'aass': 23, 'iiii': 56, 'dftj': 38}
>>> dict(jhjkhk = 433,jkhjkhk = 3434,iuijmkm = 344343)
{'jkhjkhk': 3434, 'jhjkhk': 433, 'iuijmkm': 344343}
>>> c = dict(jhjkhk = 433,jkhjkhk = 3434,iuijmkm = 344343)
>>> c
{'jkhjkhk': 3434, 'jhjkhk': 433, 'iuijmkm': 344343}
No comments:
Post a Comment