[Tutor] replacing lists with iterators

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jul 22 00:51:22 CEST 2004


> programmers would frown upon.  For instance, in one function that
takes
> two lists as arguments I used map to iterate through both lists at
the
> same time to set up a source and target for an os.system command.

Nothing wrong with that approach although list comprehensions might be
more efficient. But for your app the construction of the command lines
will likely be a tiny proportion of the total process time.

> been reading how lists, which are completed sequences, can now be
replaced
> with iterators, which are lazy sequences, to make more efficient use
of
> memory.  I would like to know how:
> *) you would use a iterator to store the source and target paths
> *) to iterate over two iterables at the same time

Frankly I wouldn't bother unless you have a huge number of files to
convert(think thousands). Iterators are neat but they require more
work than the built in lists and the built in lists are there to make
life easy!

> for fullPathToWAV, fullPathToTarget in map(None,
listOfFullPathsToWAVs,
           listOfFullPathsToTargets):

In this case zip() is more appropriate that map() with None IMHO:

for w,t in zip(listOfWAVs, listOfTargets):

Alan G.




More information about the Tutor mailing list