Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Heterogeneous lists

Reply
Thread Tools

Heterogeneous lists

 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      08-06-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.

 
Reply With Quote
 
 
 
 
Gordon Airporte
Guest
Posts: n/a
 
      08-07-2007
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?
 
Reply With Quote
 
 
 
 
Jarek Zgoda
Guest
Posts: n/a
 
      08-07-2007
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/
 
Reply With Quote
 
Tony
Guest
Posts: n/a
 
      08-07-2007
On Aug 7, 8:53 pm, Jarek Zgoda <jzg...@o2.usun.pl> wrote:
..
>
> 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

 
Reply With Quote
 
faulkner
Guest
Posts: n/a
 
      08-07-2007
On Aug 7, 2:53 pm, Gordon Airporte <JHoo...@fbi.gov> wrote:
> 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.

 
Reply With Quote
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      08-08-2007
"Gordon Airporte" <J,,,,>

> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
heterogeneous lists in C++ Willi C++ 7 03-19-2013 03:57 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
Number hierarchically across heterogeneous elements Mike XML 3 07-07-2005 06:40 PM
Validating heterogeneous XML kj XML 1 04-15-2004 06:57 PM
Heterogeneous linked structures; for a Tire search. Jason C++ 0 08-21-2003 08:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57