Am 09.03.2010 13:02, schrieb Peter Otten:
[sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y]
[1.5, 1.5, 8.0, 4.0, 4.0, 4.0]
Peter
... pwned.
Should be the fastest and shortest way to do it.
I tried to do something like this, but my brain hurt while trying to
visualize list
Am 08.03.2010 23:34, schrieb dimitri pater - serpia:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
w = [1.5, 1.5, 8, 4, 4, 4]
This
On Mar 8, 6:39 pm, John Posner jjpos...@optimum.net wrote:
On 3/8/2010 5:34 PM, dimitri pater - serpia wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while
OK, I golfed it :D
Go ahead and kill me ;)
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
def f(a,b,v={}):
try: v[a].append(b)
except: v[a]=[b]
def g(a): return sum(v[a])/len(v[a])
return g
w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]]
print(w is now the
Michael Rudolf wrote:
OK, I golfed it :D
Go ahead and kill me ;)
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
def f(a,b,v={}):
try: v[a].append(b)
except: v[a]=[b]
def g(a): return sum(v[a])/len(v[a])
return g
w = [g(i) for g,i in [(f(i,v),i) for
Michael Rudolf wrote:
Am 09.03.2010 13:02, schrieb Peter Otten:
[sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y]
[1.5, 1.5, 8.0, 4.0, 4.0, 4.0]
Peter
... pwned.
Should be the fastest and shortest way to do it.
It may be short, but it is not particularly efficient. A dict-based
On Mar 8, 2:34 pm, dimitri pater - serpia dimitri.pa...@gmail.com
wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
w = [1.5,
On Mar 9, 7:21 am, Steve Howell showel...@yahoo.com wrote:
def num_dups_at_head(lst):
assert len(lst) 0
val = lst[0]
i = 1
while i len(lst) and lst[i] == val:
i += 1
return i
def smooth(x, y):
result = []
while x:
cnt = num_dups_at_head(y)
Peter Otten wrote:
Michael Rudolf wrote:
Am 09.03.2010 13:02, schrieb Peter Otten:
[sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y]
[1.5, 1.5, 8.0, 4.0, 4.0, 4.0]
Peter
... pwned.
Should be the fastest and shortest way to do it.
It may be short, but it is not
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
w = [1.5, 1.5, 8, 4, 4, 4]
I have looked at iter(tools) and next(), but that did not help
dimitri pater - serpia wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
w = [1.5, 1.5, 8, 4, 4, 4]
I have looked at iter(tools) and
On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia
dimitri.pa...@gmail.com wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
thanks Chris and MRAB!
Looks good, I'll try it out
On Tue, Mar 9, 2010 at 12:22 AM, Chris Rebert c...@rebertia.com wrote:
On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia
dimitri.pa...@gmail.com wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c',
On 3/8/2010 5:34 PM, dimitri pater - serpia wrote:
Hi,
I have two related lists:
x = [1 ,2, 8, 5, 0, 7]
y = ['a', 'a', 'b', 'c', 'c', 'c' ]
what I need is a list representing the mean value of 'a', 'b' and 'c'
while maintaining the number of items (len):
w = [1.5, 1.5, 8, 4, 4, 4]
I have
On 3/8/2010 9:39 PM, John Posner wrote:
snip
# gather data
tally_dict = defaultdict(Tally)
for i in range(len(x)):
obj = tally_dict[y[i]]
obj.id = y[i] --- statement redundant, remove it
obj.total += x[i]
obj.count += 1
-John
--
On 3/8/2010 9:43 PM, John Posner wrote:
On 3/8/2010 9:39 PM, John Posner wrote:
snip
obj.id = y[i] --- statement redundant, remove it
Sorry for the thrashing! It's more correct to say that the Tally class
doesn't require an id attribute at all. So the code becomes:
#-
from
16 matches
Mail list logo