[Tutor] I want some help with arrays...

alejandro varas alej0varas at gmail.com
Sat May 19 20:05:38 CEST 2007


2007/5/18, Luke Paireepinart <rabidpoobear at gmail.com>:
>
> James Matthews wrote:
> > When the CPU writes to the RAM the 0th location can be written to also.
> When
> > you alter components of a language for example changing the way an list
> is
> > indexed you have to be careful because you can accidently jump out of
> > bounds!
> def indexOneBased(somelist,index):
>    return somelist[index-1]
>
> now you can do
> indexOneBased([1,2,3,4,5], 5)
> and you will get 5.
>
> Obviously the verbosity of this example seems to imply its uselessness,
> but what Bob was getting at is that there are situations where you can
> create a list that you index into based upon some arbitrary starting
> point.
> For example, say you had a calendar program that kept track of my
> schedule for days 1 through 31 of this month.
> You'd store the schedule of each day in a list starting with the 0th
> element and ending at the 30th element.
> Then, whenever I asked you for the 1st element, for example, you'd
> retrieve the 0th element for me, and so on.
> The indexing itself isn't changed, merely the interface to it.
> Note that you don't actually index the list starting at the 1th element
> (the 2nd one)
> you index it starting at the 0th element, but use indexes that begin at 1.


if you want something like a calendar i thin is beter to use adictionary
where you can do this
agenda =
{
  'month' :
  {
    'day':
    { ...
    },
  },
}

so you don't have to deal whit indexes you jut wet what you want by doing

month = "month"
day = "day"

agenda[month][day]

HTH,
> -Luke
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Alejandro Varas G.
T.N.S. en Redes de Computadores.(estudiante)
http://alej0varas.googlepages.com
+56998330920
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070519/0fdfe905/attachment.html 


More information about the Tutor mailing list