[Tutor] ***SPAM*** List to dictionary
Kent Johnson
kent37 at tds.net
Thu Dec 7 11:58:39 CET 2006
Bill Campbell wrote:
> The way I usually do this is something like:
>
> outDict = dict(map(lambda x: (x, 1), inList))
> names = outDict.keys()
> names.sort()
This is a really old approach. Since Python 2.3 you can say
outDict = dict.fromkeys(inList)
or dict.fromkeys(inList, 1) if you cared about the value.
Since Python 2.4 you can use a set instead of a dict as shown in other
replies.
Kent
More information about the Tutor
mailing list