Dict Help

Robert Rawlins robert_rawlins at hotmail.com
Sun Jul 15 10:39:24 EDT 2007


Hello Guys,
 
I'm looking for some help expanding on a dictionary I've got and storing multiple values per key and the best way to do it. I'm guessing that I need to store a list inside the value of the dictionary, but I'm not quite sure how that can be achieved, and also how to check for values in that list.
 
Here is a brief example of what I want to be able to build:
 
Key                                          Value
00:0F:DE:A8:AB:6F                     6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.gif,533EAE0F-B211-B2D8-4C2DB662CCECFBD7.3gp
00:17:B0:A0:E7:09                     6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.gif
00:1B:98:16:21:E4                     6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg
 
Now I really need to have two functions, one of which appends a value to the list for a specified key, so I have the key and the new value as strings, I then want to locate that key and append the list with the new value.
 
The second function I need, is to check for the existence of a value in the list of a particular key, again I have the key and the value and I want to do something like:
 
if value in list of values for key:
       do something here...
 
The final function that would be helpful to me would to be able to remove a value from the list for a specific key.
 
I'm not sure if a list as the value in a dict is possible, or if its the best way to achieve this, It just made logic sense to me so thought I'd come and get your thoughts on this. If anyone has any better suggestions about how to attach mutiple values to a single key, I would love to hear it. Other than that I just need some code examples of those append/existence functions.
 
Can anyone offer some help? Thanks guys,
 
Rob
_________________________________________________________________
100’s of Music vouchers to be won with MSN Music
https://www.musicmashup.co.uk/index.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070715/1cf2f4d2/attachment.html>


More information about the Python-list mailing list