473,509 Members | 7,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2054
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2137
by: Shawn Spiars | last post by:
dbWidget is a heterogeneous database development tool. It works with most relational databases, including Oracle, SQL Server, MySQL, and Sybase. dbWidget comes with a free, fully functional 30-day...
1
1331
by: kj | last post by:
The main rationale I have seen for namespace support in XML is to enable the peaceful coexistence of XML fragments from various sources within the same ("heterogeneous") XML document without their...
9
3734
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
8
2407
by: Markus Dehmann | last post by:
I defined a base class in order to put heterogeneous values into a standard container: All values that I store in the container are derived from my base class. Now when I iterate over the...
2
8047
by: Adnan | last post by:
Hi Guys, I have one stored procedure on SQL 6.5 and retrieving data from SQL 2000. I have defined a linked server on SQL 6.5. But I am getting following error:- "Heterogeneous queries require...
3
3257
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
1
1902
by: martin.zarate | last post by:
I'm working on a simple command-line app. The app takes an XML file that provides the operations to perform. However, the problem I'm running in to is that the file must contain a seperate array...
16
2575
by: Michael M. | last post by:
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = s2 = s3 = if len(s1) >= len(s2) and len(s1) >= len(s3): sx1=s1 ## s1 ist längster
2
4593
by: Arash Partow | last post by:
Hi all, I've got a question related to emulating aspects of polymorphism with CRTP. Below is a typical polymorphic class hierarchy with a definition of a "somewhat" heterogeneous container of...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.