unique unions of several dict keys

P

python

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.
 
D

Duncan Booth

(e-mail address removed) wrote in

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.
tmpDict = {}
for d in dicts:
tmpDict.update(d)
return tmpDict.keys()

['a', 'c', 'b']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top