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,
On Mar 9, 7:21 am, Steve Howell 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)
>
On Mar 8, 2: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]
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
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 comprehensi
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
On Mar 8, 6:39 pm, John Posner 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 maintaining
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 li
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 kind
On 3/8/2010 9:43 PM, John Posner wrote:
On 3/8/2010 9:39 PM, John Posner wrote:
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 collect
On 3/8/2010 9:39 PM, John Posner wrote:
# 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
--
http://mail.python.org/mailman/listinfo/python-li
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 looke
thanks Chris and MRAB!
Looks good, I'll try it out
On Tue, Mar 9, 2010 at 12:22 AM, Chris Rebert wrote:
> On Mon, Mar 8, 2010 at 2: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
On Mon, Mar 8, 2010 at 2: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,
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
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 me
16 matches
Mail list logo