Newbie question: eliminating entries in dict

sean sean_berry at
Wed Nov 26 03:20:20 CET 2003

I had tried something very similar to that but ended up with the same error
I am getting now.

Traceback (most recent call last):
  File "C:\Python23\", line 93, in -toplevel-
    d = ([(k,v) for k, v in a.iteritems() if (k.split("*", 1)[1]) not in b])
IndexError: list index out of range

Changing the [1] to a [0] makes the Error go away, but compares the wrong
part of the entry.

Any ideas?

"sean" <sean_berry at> 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
> 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
> Also searched the mailing list archives and newsgroups and could not come
> 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