星期六, 八月 14, 2010

python3.0 dictionary key order

In fact, the dictionary object that is key - the value of the following is a dictionary object to add, modify, delete (modify and add the same way, when the key does not exist when the value added)

IDLE 3.0
>>> Dic = ("aa": 1, "bb": 2, "ab": 3)
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2)
>>> For k in sorted (dic.keys ()):
print (k)

aa
ab


-----------------------------------------------
In fact, the dictionary object that is key - value pairs
The following is a dictionary object to add, modify, delete
(Modify and add the same way, when the key does not exist when the value added)
>>> Dic ["cc"] = 4
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2)
>>> Dic ["bc"] = 5
>>> Dic
('Aa': 1, 'cc': 4, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Dic ["cc"] = 6
>>> Dic
('Aa': 1, 'cc': 6, 'ab': 3, 'bb': 2, 'bc': 5)
>>> Del dic ["cc"]
>>> Dic
('Aa': 1, 'ab': 3, 'bb': 2, 'bc': 5)

没有评论:

发表评论