How does "for" work?

Alex Martelli aleaxit at yahoo.com
Wed Oct 11 18:45:25 EDT 2000


"Steve Juranich" <sjuranic at condor.ee.washington.edu> wrote in message
news:Pine.SOL.3.96.1001011131237.10163C-100000 at condor.ee.washington.edu...
    [snip]
> > rather than a list?  Using it correctly with a for-loop requires
> > that the keys be a compact set of integers from 0 upwards -- and
> > in this case, what do you gain by making it a dictionary rather
    [snip]
> self.data is a time-indexed bunch of data structures.  I would have used a
> list, but I wanted to allow for start times != 0.  I know that in the
other
> "P" language, it allows re-defining the start index of a list.  Has Python
> implemented a similar bad idea?

No, list-index always starts from 0 in Python.  But then, you DO need
the first index to be 0 if the object is to be iterated on with a for
statement -- that one calls the __getelement__ method starting from
0, too.  So, a list, plus a separate 'actual start index', seems a
better solution than an array.


Alex






More information about the Python-list mailing list