[Tutor] extracting lists from lists of lists

Kent Johnson kent_johnson at skillsoft.com
Tue Sep 14 16:12:23 CEST 2004


I still don't understand why you can't use a simple class for this. You can 
pass around instances of the class instead of tuples. You can make lists or 
sets of class instances when you need more than one.

Or if you decide to use a dict, you can pass that directly to clients 
instead of making it into a tuple.

Can you give an example of how you will use the tuples?

Finally, you might be interested in some recipes in the online Python 
Cookbook (http://aspn.activestate.com/ASPN/Cookbook/Python) for making 
tuples with named members. They are immutable though, I think you said you 
want users to be able to change the values.

Kent

At 03:45 PM 9/14/2004 +0200, nik wrote:
>Kent Johnson wrote:
>
>>At 12:52 PM 9/14/2004 +0200, nik wrote:
>>
>>>hi,
>>>
>>>I have a class which is just a holder for a data structure, and for some 
>>>reason I've decided to hold the data in the following form;
>>>
>>>class myData:
>>>    data = [  ["name", ""], ["age", ""], ["gender", ""] ]
>>>
>>>I'm not totally sure it's the best way, but it strikes me as something 
>>>that can be easily manipulated into maps etc. I had started out with
>>>class myData:
>>>    name = ""
>>>    age = ""
>>>    gender = ""
>>>
>>>but I found that I had to put most of those items into lists to do 
>>>anything with them.
>>
>>
>>What kinds of things are you doing that you need these values in a list? 
>>It sounds like maybe you are trying to pull the data out of the class to 
>>pass to another function, but maybe it would be better to pass the class 
>>itself around? Or maybe you should get rid of the class entirely and just 
>>use a dictionary.
>
>I'm thinking in terms of a C struct -  it's a handy parcel to move a set 
>of data around, and quite likely there'll be stacks of sets. There's no 
>extra functionality required from the set, and I'm not planning on 
>deriving any other classes from this one. The dictionary seems a very good 
>idea, but I think I still need to put it into a class since I'll have 
>multiple instances of it - is that right? or can I do the equivalent of a 
>typedef?



More information about the Tutor mailing list