itertools.imap vs map over the entire iterable

Viewed 8597

I'm curious about a statement from http://docs.python.org/2/library/itertools.html#itertools.imap, namely it describes

sum(imap(operator.mul, vector1, vector2))

as an efficient dot-product. My understanding is that imap gives a generator instead of a list, and while I understand how it would be faster/consume less memory if you're only considering the first few elements, with the surrounding sum(), I don't see how it behaves any differently than:

sum(map(operator.mul, vector1, vector2))
4 Answers
Related