[Tutor] creating a list of data . . .

Kirk Bailey idiot1 at netzero.net
Mon Aug 25 23:17:57 EDT 2003


KIRK! KIRK! KIRK! (counting the cadence by pounding on crt with a large fuzzy 
stuffed monkey from the bookshelf to the right...) :-)

Scottish, not German!
(Dad's band of vikings went north, not east.)

But read on, this is more than a egotistical rant.

Don Arnold wrote:

> ----- Original Message -----
> From: <Futurug at aol.com>
> To: <tutor at python.org>
> Sent: Monday, August 25, 2003 8:00 PM
> Subject: [Tutor] creating a list of data . . .
> 
> 
> 
>>Thank you for
>>
>>I am absolutely new to programming with python, and I am learning quickly
>>
>>I am trying to create a tuple with 14 data in.
>>
>>my current code:
>>
>>    frug = frug , rug
>>
>>where frug is the final tuple and rug is the data I am trying to add
>>
>>I curretly get all 14 fields of data, but it only lets me call up
whups, this escaped me earlier. you can only access PART of it? data is acessed 
numerically, just like a list, address starting with 0 of course.  If you can't 
access all of it at will, something is TERRIBLY WRONG.
>>
>>I do not want to create one long string of data as the length of the
>>individual data fields can vary.
Right. You want some form of data construct that contains each datum in it's own 
'cell', and you simply access that cell.
>>
>>Thanks
>>
>>Kenny Sodbuster
> 
> 
> As Kurt has pointed out, tuples are immutable: once they're created, they
> can't be modified. They can, however, be rebound:
> 
KIRK! And rebinding is a pain.

> someTuple = ()
> 
> for i in range(10):
>     someTuple = someTuple + (i,)
> 
> print someTuple
> 
> 
>>>>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
> 
> 
> Lists, on the other hand,  _are_ mutable, so it's often cleaner (and more
> efficient) to build a list and then convert it to a tuple when you're done:
> 
Also reccomended in some tutorials.

> someList = []
> 
> for i in range(10):
>     someList.append(i)
> 
> someOtherTuple = tuple(someList)
> 
> print someOtherTuple
> 
> 
Veryfine, and much preferred to messing with tuples. Turn it into a list, play 
with the list, then turn it into a tuple- which is meaning what I said, but at 
much greater detail and length: Destroy it and recreate it.

>>>>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
> 
> 
> 
> HTH,
> Don
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Promethieus
  +                              think                                +

Fnord.




More information about the Tutor mailing list