Newbie question: eliminating entries in dict

sean sean_berry at cox.net
Tue Nov 25 21:34:47 EST 2003


I don't understand how this would be possible since I am splitting the entry
into two parts, shouldn't the index of 1 always exist?

"sean" <sean_berry at cox.net> wrote in message
news:avSwb.7451$9O5.1937 at fed1read06...
> 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