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

Luke Paireepinart rabidpoobear at gmail.com
Sat May 19 21:20:12 CEST 2007

[snip my calendar example about fake 1-based indexing]
> 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"
And what is day?
Is it, perhaps, a number, such as 1-31?
That sounds like an index to me.
Your example's better in the sense that you save a bit of storage if you 
don't have a schedule for every day.
But it's not conducive to the example I was trying to give.

My original example was for the schedule for a particular month, not for 
a particular year.
The purpose of the example was to show a situation where you could use 
1-based indexing
into a 0-based array.  And if I made the example use a dictionary, the 
purpose of the example
would have been lost.

I never said that my method of solving this particular problem was the best.
It's like, how in school, they teach you recursion using factorial and 
summing sequences,
when, really, factorial can be done linear and iterative, and sequences 
can even be done in constant time,
depending on the sequence.
It's not that that's the best solution.  It's that it's a solution that 
uses the tool you're trying to give people
experience with.  The intent is that they extrapolate from that the 
general usefulness of the technique
(be it recursion or munging with indexes)  so that, later, they will 
hopefully be able to recognize the situation
where it's better to do it a different way.  Giving them more tools on 
their belt so they're more versatile
and thus, hopefully, better programmers in the end.

Hope That's Clear,

More information about the Tutor mailing list