字典
一,映射类型:字典
1,字典的创建
   手动创建:
      dict1={}
      dict2={"name":"earth","port":80}
      dict1,dict2
      结果: ({}, {'name': 'earth', 'port': 80})
      为什么会返回一个元组呢?
   函数创建:
      dict:
>>> a=("x",1,"y",2)
>>> fdict=dict(a)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 1; 2 is required
>>> fdict=dic(a)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
NameError: name 'dic' is not defined
>>> fdict=dict(a)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 1; 2 is required
>>> a=(["x",1],["y",2])
>>> fdict=dict(a)
>>> fdict
{'y': 2, 'x': 1}
2,访问字典中的值
   若想遍历一个字典,你只需要循环查看他的键:
   dict2={"name":"earth","port":80}
   for key in dict2:
       print "key=%s, value=%s" %(key,dict2[key])
   dict2={"name":"earth","port":80}
   for key,value in dict2.items():
       print "key=%s, value=%s" %(key,value)
   这里就有一个关键函数需要记住:items()
   根据Key来获取value
   dict2["name"]
   判断key,是否在字典中(in , not In) 声明:字典中value是没有办法通过此种方法进行判断的
   通过函数判断
   has_key("name")
3,如何更新字典
   dict2["name"]="server"    更新现有条目
   dict2["port"]="6969"      更新现有条目
   dict2["arch"]="sunos5"    增加新条目
4,如何删除字典元素和字典
   del dict2["name"]         删除现有条目
   dict2,clear()             保存dict1字典,但删除所有条目
   del dict2                 删除整个字典
   dict2.pop("name")         删除指定的key,返回值
     注意:字典的pop()函数与列表中的不同
     >>> a=["x",1,"y",2]
     >>> a.pop()
         2
     列表中的pop()函数只删除最后一个值.
二,映射类型操作符
1,标准类型操作符
 dict4 < dict5
2,字典的键查找操作符
 []
3,(键)成员关系操作.
三,映射类型的内建函数和工厂函数
1,标准类型函数
   type()
   str()
   cmp()
四,映射类型内建方法
dict.clear()
dict.get()
dict.has_key()
dict.items()
dict.keys()
dict.iter()
dict.pop()
dict.update()
dict.values()