How does "for" work?

Steve Juranich sjuranic at condor.ee.washington.edu
Wed Oct 11 16:15:27 EDT 2000


On Wed, 11 Oct 2000, Alex Martelli wrote:

> I see that other posts have already remarked that you need to
> change the KeyError exception (returned by addressing the self.data
> dictionary with a missing key) into an IndexError (which is what
> a sequence returns, and for expects), but I'd like to understand
> better what you're doing.  _Why_ is self.data a dictionary at all,
> 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
> than a list in the first place?
> 

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?

----------------------------------------------------------------------
Stephen W. Juranich                         sjuranic at ee.washington.edu
Electrical Engineering         http://students.washington.edu/sjuranic
University of Washington             http://rcs.ee.washington.edu/ssli





More information about the Python-list mailing list