Deleting dictionary items
Will Newton
will at nospam.misconception.org.uk
Sun Mar 18 15:21:20 EST 2001
Andreas Jung wrote:
> # What td.data ? I assume td.data is your dictionary ?
> # item is now a tuple (x1,x2,x3...)
>
>> if item[attr] != value:
>
> # you can access the tuples elements by their position
> using the [] operator
> # e.g. item[0] gives x1, item[1] gives x2 ...
> #
>> del td.data[item]
>
> # This should work
This makes me think, would it be a sane way of doing things to use a list
comprehension to modify a dictionary?
(I can't use it now, as I am stuck with 1.5.2 for the foreseeable future)
e.g.
filter(dict, lambda key: key == value)
or in my case a little more complex:
filter(dict, lambda key: key[attr] == value)
Is this possible? Desireable? Too stupid to contemplate?
More information about the Python-list
mailing list