dict.has_key(x) versus 'x in dict'

Andy Dingley dingbat at codesmiths.com
Wed Dec 6 10:28:52 EST 2006


Paul Melis wrote:
> I've always been using the has_key() method to test if a dictionary
> contains a certain key. Recently I tried the same using 'in', e.g.

I've found using the set type to be the quickest way to do many of
these tasks. That leads me to another problem: how to cast / convert
sets as something else afterwards


What's the best (i.e. Pythonic) way to do this?
I need to generate a set (lots of intersections involved), but then I
need to display it sorted

        lstBugsChanged = [ bugId for bugId in setBugsChanged ]
        lstBugsChanged.sort()




More information about the Python-list mailing list