[Tutor] working with multiple sets

Kent Johnson kent37 at tds.net
Wed Sep 9 19:19:45 CEST 2009


On Wed, Sep 9, 2009 at 7:48 AM, kevin parks <kp8 at mac.com> wrote:

> Then i can cast it as a dict and pick over that dictionary as i wish.

There is no need for that. defaultdict is a subclass of dict and
supports all the methods of dict.

> Here
> (as a bonus) I can transverse a range of keys that is inclusive of all my
> keys and also use python's get() dict method to also indicate index points
> (keys) that are empty.. which by default returns 'None', which is also
> useful in this case to show me what is missing. But I also have to do some
> type testing tomfoolery since missing keys return None, which is a special
> type (and not a list like the others)... I wanted the value list sorted
> so... i did  if type(item) == type(foo): .... not sure if there is a
> betterererer way.

Besides Lie's suggestions, you could use
       item = gamut.get(x, [])
       item.sort()
       print x, item

Kent


More information about the Tutor mailing list