That's two new things I've learnt. I didn't realise that for loops could be used like that (with more than one... key?).
Thanks, I'm changing my code even now! On 19 April 2010 00:09, Alan Gauld <alan.ga...@btinternet.com> wrote: > > "C M Caine" <cmca...@googlemail.com> wrote > >> for i in range(len(timetable)): >> numDict[timetable[i]] += 1 >> if spaceDict['1st'+timetable[i]] == 0: >> spaceDict['nth'+timetable[i]] = i > > for index, item in enumerate(timetable): > numDict[item] += 1 > if spaceDict['1st'+item] == 0: > spaceDict['nth'+item] = i > >> >> This function works fine, but I think that using range(len(timetable)) >> is clumsy. On the other hand, I need the indexes to track the number > > enumerate() is your friend. > > > HTH, > > Alan G > > _______________________________________________ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor