[Tutor] ***SPAM*** List to dictionary

Bill Campbell bill at celestial.net
Thu Dec 7 06:11:40 CET 2006


On Wed, Dec 06, 2006, Morpheus wrote:
>I'm new to programming, and trying to learn the Python language.  
>The following code does what I want it to do, but I have not idea how it
>works.  
>
>def scanList(names,temp):
>    for i in names:
>        temp[i] = 0
>    print temp
>
>Names = []
>temp = {}
>
>I have a list of names (Names[]) and want to remove duplicate names in
>the list.  Here is what I think is happening (please correct me if I'm
>wrong, or using the wrong technical terminology):  I'm passing the
>variables Names and temp as arguments to the scanList function.  The
>statement (for i in names:) is an iteration going through each item in
>the list.  The next statement (temp[i] = 0) is where I get confused.
>Can someone please explain what is happening here.  

The way I usually do this is something like:

outDict = dict(map(lambda x: (x, 1), inList))
names = outDict.keys()
names.sort()

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``Find out just what people will submit to, and you have found out the
exact amount of injustice and wrong which will be imposed upon them; and
these will continue until they are resisted with either words or blows, or
both. The limits of tyrants are prescribed by the endurance of those whom
they oppress.'' -- Frederick Douglass.


More information about the Tutor mailing list