Heterogeneous lists
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Aug 6 01:56:32 EDT 2007
Gordon Airporte a écrit :
> This is one of those nice, permissive Python features but I was
> wondering how often people actually use lists holding several different
> types of objects.
Depends on the definition of 'type'. I often have instances of different
- possibly unrelated - classes in a same list. Fact is that these
instances usually share a common (implied) interface, but, well,
sometimes they don't...
> It looks like whenever I need to group different objects I create a
> class, if only so I can use more meaningful names than '[2]' for the items.
You may not know, but Python has a builtin dict (ie : hashtable) type.
It's very handy when you just want to "group different objects" while
still using meaningful names.
More information about the Python-list
mailing list