[Tutor] Counting help

Python python at venix.com
Wed Aug 24 00:28:36 CEST 2005

listofnames = nameofsender[0], 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
	listofnames.insert(0, nameofsender[0])

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

Lloyd Kvam
Venix Corp

More information about the Tutor mailing list