[Tutor] Trying to enter text from a file to a Dictionary

Alan Gauld alan.gauld at freenet.co.uk
Fri Jan 27 19:36:27 CET 2006


>> for line in f:
>>     if isDefinition:
>>        gloss[currentKey] = line
>>        currentKey = None
>>        isDefinition = False
>>     else:
>>        currentKey = line
>>        isDefinition = True
>>   
> Or you can use next():
> 
> for line in f:
>    gloss[line] = f.next()

Ah! Indeed you can. I'd forgotten about that neat feature of iterators. 
No longer are for loops broken when you mess around with the 
iterated item.

Good catch Bob.

Alan G.





More information about the Tutor mailing list