469,641 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,641 developers. It's quick & easy.

Heterogeneous lists

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
5 1863
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
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
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
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
"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.

Similar topics

1 post views Thread by kj | last post: by
9 posts views Thread by Dave H | last post: by
8 posts views Thread by Markus Dehmann | last post: by
2 posts views Thread by Adnan | last post: by
3 posts views Thread by s_subbarayan | last post: by
1 post views Thread by martin.zarate | last post: by
16 posts views Thread by Michael M. | last post: by
2 posts views Thread by Arash Partow | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.