Andrew Koenig wrote: >>IMO it would be clearer, and equally elegant, to write >>this as something like >> >> for i in indices(myList): >> ... > I think that > > for i in myList.keys(): > > would be even better, because it allow the same usage for dict and list. Of > course that wouldn't generalize to other sequences that support len. Wouldn't be better then that indices returns the keys for a dictionary instead? It would then support all these sequences. Maybe an index is not the good term to generalize, but I don't think key is really better, particularly since I would expect the use of a dictionary to be more rare. Maybe another function, let's say accesses, could be used for these rare cases, adding no overhead for common cases of indices: for key in accesses(myDict): pass for index in accesses(myList): pass But since iterating through a dictionary means to iterate through the keys, while it means to iterate through the elements for a list, would that be really uniform to support generalization with dictionaries? Is it useful? Regards, Nicolas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4