31-08-2009 o 22:28:56 Jan Kaliszewski wrote:
>>> setup = "from itertools import starmap, imap ; from operator
import mul; import random, string; names = [rndom.choice(string.
ascii_letters) for x in xrange(1)]; hours = [random.randint(
1, 12) for x in xrange(1000)]; m = zip(names, hours); w
31-08-2009 o 18:19:28 vsoler wrote:
Say
m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
r={'a':4, 'b':5, 'c':6}
What I need is the calculation
1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26
That is, for each row list in variable 'm' look for its first element
in variable 'r' and multiply
vsoler writes:
> m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
> r={'a':4, 'b':5, 'c':6}
>
> What I need is the calculation
>
> 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26
sum(r[k]*w for k,w in m)
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 31, 6:59 pm, Tim Chase wrote:
> vsoler wrote:
> > On Aug 31, 6:30 pm, Tim Chase wrote:
> >>> After simplifying my problem, I can say that I want to get the sum of
> >>> the product of two culumns:
> >>> Say
> >>> m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
> >> assuming you meant ['c', 3]
vsoler wrote:
On Aug 31, 6:30 pm, Tim Chase wrote:
After simplifying my problem, I can say that I want to get the sum of
the product of two culumns:
Say
m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
assuming you meant ['c', 3] here...^> r={'a':4, 'b':5, 'c':6}
What I need is the
On Aug 31, 6:30 pm, Tim Chase wrote:
> > After simplifying my problem, I can say that I want to get the sum of
> > the product of two culumns:
>
> > Say
> > m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
>
> assuming you meant ['c', 3] here... ^> r={'a':4, 'b':5, 'c':6}
>
> > What I need
After simplifying my problem, I can say that I want to get the sum of
the product of two culumns:
Say
m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
assuming you meant ['c', 3] here...^
r={'a':4, 'b':5, 'c':6}
What I need is the calculation
1*4 + 2*5 + 3*4 = 4 + 10 + 12 =