[Tutor] list.__init__()

Kent Johnson kent37 at tds.net
Thu Jan 26 21:38:51 CET 2006

Christopher Spears wrote:
> What purpose does list.__init__() play in the piece of
> code below?

It's an incorrect call to the base class __init__() function. This does 
base class initialization on the current list. The correct call is

By the way this list seems to be doing the work of a set. Since Python 
2.3 set types have been standard in Python (in module sets in 2.3 and 
the builtin type set in 2.4). Before 2.3 a dict is a better choice for 
rolling your own because it supports fast lookup.

> class Mylist(list):
> 	def __init__(self, value = []):
> 		list.__init__([])
> 		self.concat(value)
> 	def concat(self, value):
> 		for x in value:
> 			if not x in self:
> 				self.append(x)
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list