1.PYTHON調用hash()函數來判斷鍵的可用性,鍵能夠是數字,字符串甚至是元祖python
2.PYTHON內置字典dict,在其它語言中也稱爲map,使用鍵值對存儲,具備極快的查詢速度,不管這個表有多大,查詢速度都不會變慢,由於dict的實現原理和查字典同樣函數
3.PYTHON一個KEY只能對應一個value,若是屢次把不一樣的值給同一個key,後面的值會把前面的值沖掉,若是key不存在dict報錯可用in/dict.get(,default)解決spa
4.PYTHON字典內部存放的順序和key存放的順序沒有關係,若是想實現按照字典的key插入的順序排列可調用collections模塊兒的OrderedDict類實現.net
# -*- coding: utf-8 -*- """ # # Authors: limanman # OsChina: http://my.oschina.net/pydevops/ # Purpose: # """ import sys def main(): """Main function.""" # create dict generate_dict = { 'name': 'limanman', 'age': 25, 'sex': 'man', } generate_dict = dict() generate_dict = {}.fromkeys( ('name', 'age', 'sex'), None ) generate_dict = dict([ ('name', 'limanman'), ('age', 25), ('sex', 'man'), ]) generate_dict = dict(name='limanman', age=25, sex='man') # update dict generate_dict['name'] = 'liuzhenzhen' generate_dict.update({ 'name': 'limanman', }) # access dict(recommand) for key in generate_dict: print '%-10s%-s' % (key, generate_dict[key]) # access dict(not recommand) for key, val in generate_dict.iteritems(): print '%-10s%-s' % (key, generate_dict[key]) # delete dict del generate_dict['name'] generate_dict.pop('age') del generate_dict if __name__ == '__main__': main()