[Tutor] Counting help
python at venix.com
Wed Aug 24 00:28:36 CEST 2005
listofnames = nameofsender, listofnames
does not add a name to a list. Rather it creates a tuple of the new
name and the list and then binds the tuple to the list name. That's why
you wind up with the lisp style list.
To add a name to the head of the list use
If you are using a version of Python that supports sets, using sets
would be much simpler since the duplicates get discarded automatically.
import sets # python2.3
setofnames = sets.Set()
len(setofnames) # count of distinct names
More information about the Tutor