By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,554 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,554 IT Pros & Developers. It's quick & easy.

Heterogeneous lists

P: n/a
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.
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.
How often do these show up in your code?
Is this simply the upshot of the underlying arrays holding only object
references of some sort?
Aug 7 '07 #1
Share this Question
Share on Google+
5 Replies

P: n/a
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.

Aug 7 '07 #2

P: n/a
Bruno Desthuilliers napisa³(a):
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...
I love my lists of classes. I know, I'll go to hell for that.

--
Jarek Zgoda
http://jpa.berlios.de/
Aug 7 '07 #3

P: n/a
On Aug 7, 8:53 pm, Jarek Zgoda <jzg...@o2.usun.plwrote:
..
>
I love my lists of classes. I know, I'll go to hell for that.

--
Jarek Zgodahttp://jpa.berlios.de/
And I love my shelved lists of classes..

Tony

Aug 7 '07 #4

P: n/a
On Aug 7, 2:53 pm, Gordon Airporte <JHoo...@fbi.govwrote:
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.
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.
How often do these show up in your code?
Is this simply the upshot of the underlying arrays holding only object
references of some sort?
how else would you implement an n-ary tree? eg, AST, CST, minimax, GP.

Aug 7 '07 #5

P: n/a
"Gordon Airporte" <J,,,,r@fbi.gov>
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.
I do it all the time - I only use tuples when I _have_ to.
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 don't have to be so array-minded. You can write things like:

address = 2
individual_list[address]

this is easier to read and understand than:

individual_list[2]

and does the same thing.

I have found that the most useful data structure is a dict,
or a dict of dicts. - almost an instant database.

- Hendrik

Aug 8 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.