Lists and Tuples

Skip Montanaro skip at pobox.com
Fri Dec 5 15:24:01 EST 2003


    Roy> That's a good example, because it makes for a nice segue.  If you
    Roy> were holding data from a form that looked like:

    Roy> Street: ___________________________
    Roy>   City: ___________________________
    Roy>  State: ___________________________
    Roy>    Zip: ___________________________

    Roy> Then I agree you're looking at a 4-tuple (assuming you didn't want
    Roy> to go whole-hog and define an Address class).  But, imagine a
    Roy> somewhat more generic form that looked like:

    Roy> Address line 1: ________________________
    Roy> Address line 2: ________________________
    Roy> Address line 3: ________________________
    Roy> Address line 4: ________________________

    Roy> You might fill in exactly the same data, but now if feels like it
    Roy> should be a list.

I think you're thinking too hard.  ;-) What about:

    Street 1: ___________________________
    Street 2: ___________________________
    Street 3: ___________________________
        City: ___________________________
       State: ___________________________
         Zip: ___________________________

?  I might use a tuple containing a list.  Of course, in some situations,
the "natural form" your data takes has other external influences.  If I was
storing addresses in a SQL table I might use a tuple of five strings (one
per column in the database) and just suffer with the fact that I couldn't
have more than three street elements.  If addresses were stored in a pickle
file, I'd might go with a tuple containing a list and three strings.

have-we-completely-snowed-the-OP-yet?-ly, y'rs,

Skip





More information about the Python-list mailing list