Newbie question: eliminating entries in dict

sean sean_berry at
Wed Nov 26 01:31:05 CET 2003

I have two dictionaries.

a = {'a1': 1, 'a2': 5, 'a3': 2, 'a4': 7}
b = {'something*a4': 1, 'something*something': 1,
'somethingelse*somethingelse': 1, 'something*a1: 1}

What would be an efficient way of eliminating all entries in b which contain
an entry from a.

Such that the result would be

c = ['something*something', 'somethingelse*somethingelse']

or better still
c = {'something*something': 1, 'something*something': 1}

I tried a few different approaches, but they seem very long and unnecessary.
Also searched the mailing list archives and newsgroups and could not come up
with anything.

I know that I will need to compare the .split("*", 1)[1] part of b with
those from a, but am not sure
how to implement it.

Thanks in advance for any help

More information about the Python-list mailing list