"Tuples are for heterogeneous data, lists are for homogeneous data."

ajsiegel at optonline.net ajsiegel at optonline.net
Wed Mar 12 12:53:54 EST 2003


Lulu writes - 

>I think perhaps you are thinking of "homogeneous" in too narrow a sense.

>Data that is homogeneous in a Pythonic way isn't necessarily all
>integers, or all strings. Rather, a list is a bunch of things that you
>might loop over, treating each element in the "same way."

> etc.

That explanation helps.  I - a bit ironically  - am perhaps thinking in a more technical sense.  The object in a list that I am calling "heterogenous" might all descend from a common base class and all contain a method of the same name which I might call in iterating over the list.

In Java I believe I had to do all kinds of casting shenanigans to accomplish this - which is why I think of them as "heterogenous" in some sense.  More naturally, the objects do seem to me to be homogenous - which is why they work in a list.  Which is a tautology in some sense, but also coincides with your point - I think.

Art 






More information about the Python-list mailing list