Re: [Tutor] Summing part of a list

2006-05-09 Thread Matthew Webber
Thanks Kent, I liked the generator solution (I knew there had to be something like that). -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: 09 May 2006 17:54 Cc: tutor@python.org Subject: Re: [Tutor] Summing part of a list <<

Re: [Tutor] Summing part of a list

2006-05-09 Thread Matthew Webber
To expand on my original posting, I came up with this code which works ok : count_country_aggregated = [cc for cc in count_country if cc[1]>3] count_country_aggregated.append(('OTHER',sum([cc[1] for cc in count_country if cc[1]<=3]))) But it uses 2 list comprehensions (therefore 2 passes of the o

Re: [Tutor] Summing part of a list

2006-05-09 Thread Bob Gailer
Matthew Webber wrote: > I have a list that looks a bit like this - > > [(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299), > (u'fin', 6), (u'ven', 6), (u'chi', 3), (u'hun', 3), (u'mar', 3), > (u'lux', 2), (u'smo', 2), (u'tch', 2), (u'aho', 1), (u'ber', 1)] > > The list items are tuples

Re: [Tutor] Summing part of a list

2006-05-09 Thread Kent Johnson
Matthew Webber wrote: > I have a list that looks a bit like this - > > [(u'gbr', 30505), (u'fra', 476), (u'ita', 364), (u'ger', 299), > (u'fin', 6), (u'ven', 6), (u'chi', 3), (u'hun', 3), (u'mar', 3), > (u'lux', 2), (u'smo', 2), (u'tch', 2), (u'aho', 1), (u'ber', 1)] > > The list items are tuple