dictionary quetion

张少驰 zhangsc at neusoft.com
Tue Dec 4 06:24:16 CET 2001


Hello!
  I have a question about python's dictionary,I have a dictionary type variable,
such as 
dbs={'xk.dhs.org': '166.111.177.77', 'www.symantec.com':'202.112.237.39', 'ftp.happynet.org':'166.111.160.7'}
When I input dbs['www.symantec.com']='202.112.237.15',I want to get the result like that:
dbs={'xk.dhs.org': '166.111.177.77', 'www.symantec.com':['202.112.237.39','202.112.237.15'],'ftp.happynet.org':'166.111.160.7'}
How to realize this function? 

When I input dbs['www.symantec.com']='202.112.237.39',how to determine if this item has exists in dbs,if item has existed, the result is still like this:
dbs={'xk.dhs.org': '166.111.177.77', 'www.symantec.com':['202.112.237.39','202.112.237.15'],'ftp.happynet.org':'166.111.160.7'}
if item doesn't exist,then insert new value into dbs,How to realize this function?

When I print dbs,I like the result as follows:  
'xk.dhs.org': '166.111.177.77'
'www.symantec.com':'202.112.237.39'
'www.symantec.com':'202.112.237.15'
'ftp.happynet.org':'166.111.160.7'
 How to realize these function?

         Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20011204/09d62db0/attachment.html>


More information about the Python-list mailing list