By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

unique unions of several dict keys

P: n/a
Hi-
I have several different dictionaries. I want to make a unique list of
all the keys in all the dictionaries. What would be the best way of doing
that?
Thanks.
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
py****@sarcastic-horse.com wrote in
news:ma**********************************@python.o rg:
I have several different dictionaries. I want to make a unique list
of all the keys in all the dictionaries. What would be the best way
of doing that?


Create a new empty dictionary then use the update method on it for each of
other dictionaries. The keys of that dictionary are the values you want.

e.g.
def UniqueKeys(*dicts): tmpDict = {}
for d in dicts:
tmpDict.update(d)
return tmpDict.keys()
print UniqueKeys({ 'a':1, 'b': 2 }, {'b': 3, 'c': 4})
['a', 'c', 'b']


--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.