append to the end of a dictionary

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Tue Jan 24 10:25:28 EST 2006


Yves Glodt:
>I would need e.g. this:
>(a list of ports and protocols, to be treated later in a loop)
[...]
>What would be the appropriate pythonic way of doing this?

In the case of tcp and udp ports, it's the combination of protocol and
port number that's unique, not the port number by itself.

So you could create a dictionary with a tuple (protocol, port) as key, and
whatever data you need to associate with it as value.

mydict = { ('udp',5631): 'value1', 
	   ('tcp',3389): 'value2' }

-- 
René Pijlman



More information about the Python-list mailing list