473,837 Members | 1,677 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 2068
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.go vwrote:
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
2162
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 trial and is available for download at http://www.yazoosoft.com
1
1345
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 trampling over each other's namespaces. What about the validation of such "heterogeneous" XML documents? Not only are various fragments probably governed by different syntaxes, but these syntaxes are probably specified using different...
9
3759
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? Here is an example of just such a usage: <dl class="faq"> <di>
8
2429
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 elements of the container and want my original values back - can I avoid excessive casting and if statements? (see my sample code below.) Can I make it more elegant? #include <iostream> #include <vector>
2
8077
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 the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query."
3
3277
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 will be a "perfectly shuffle" of the lists together into a single list. The new list should consist of consecutively alternating nodes from both lists.Note that both these linked lists have same kind of data structure in their nodes.
1
1912
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 for each class of operations it supports, even though all operations implement the same execution interface (IModule implements Execute and PostProcess), but have wildly different configuration members. Because each module is very different to...
16
2613
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
4617
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 objects. class poly_base { public: virtual int foo(int i, int j) = 0; };
0
9852
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10902
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.