substituting list comprehensions for map()

Tim Chase python.list at tim.thechases.com
Wed Nov 4 06:43:30 EST 2009


Steven D'Aprano wrote:
> On Tue, 03 Nov 2009 22:43:45 -0600, Robert Kern wrote:
>> Or use the appropriate libraries:
>>
>> from numpy import dot
>>
>> scalar = dot(vec1, vec2)
> 
> 
> Why would I want to use an already existing library that is fast, well-
> written and well-supported, when I can toss together a nasty kludge 
> myself?

because you want to perform a dot-product on strings?

   >>> dot_product(['a', 'b', 'c'], [2,3,4])
   'aabbbcccc'

[grins, ducks and scampers away after the 
sum-shouldn't-special-case-strings-with-an-error thread]

-tkc






More information about the Python-list mailing list