Re: Filtering a Python list to uniques

2008-03-27 Thread Furkan Kuru
lstOne = [ 'A', 'B', 'C', 'C' ] dct = {} for item in lstOne: if dct.has_key(item): dct[item] += 1 else: dct[item] = 1 On Thu, Mar 27, 2008 at 10:51 PM, Kelly Greer <[EMAIL PROTECTED]> wrote: > I'm in Python 2.4.4 > > And it works for me in the Python Shell like you just > did. Let

Re: Filtering a Python list to uniques

2008-03-26 Thread Gabriel Genellina
En Wed, 26 Mar 2008 15:50:30 -0300, kellygreer1 <[EMAIL PROTECTED]> escribió: > On Mar 26, 5:45 am, hellt <[EMAIL PROTECTED]> wrote: >> On 26 ÍÁÒ, 02:30,kellygreer1<[EMAIL PROTECTED]> wrote: >> >> > What is the best way to filter a Python list to its unique members? > How come the Set() thing s

Re: Filtering a Python list to uniques

2008-03-26 Thread Jerry Hill
On Wed, Mar 26, 2008 at 2:50 PM, kellygreer1 <[EMAIL PROTECTED]> wrote: > How come the Set() thing seems to work for some people and I get the > 'unhashable' error? > > How do you test for 'membership' on a dictionary? > > # where tmp is the non-unique list > # dct is a dictionary where each u

Re: Filtering a Python list to uniques

2008-03-26 Thread kellygreer1
On Mar 26, 5:45 am, hellt <[EMAIL PROTECTED]> wrote: > On 26 ÍÁÒ, 02:30,kellygreer1<[EMAIL PROTECTED]> wrote: > > > What is the best way to filter a Python list to its unique members? > > I tried some method using Set but got some "unhashable" error. > > > lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] > > #

Re: Filtering a Python list to uniques

2008-03-26 Thread hellt
On 26 мар, 02:30, kellygreer1 <[EMAIL PROTECTED]> wrote: > What is the best way to filter a Python list to its unique members? > I tried some method using Set but got some "unhashable" error. > > lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] > # how do i reduce this to > lsttwo = [ 1, 2, 3, 4, 5, 6 ] > > Is

Re: Filtering a Python list to uniques

2008-03-26 Thread Raymond Hettinger
On Mar 25, 4:30 pm, kellygreer1 <[EMAIL PROTECTED]> wrote: > What is the best way to filter a Python list to its unique members? > I tried some method using Set but got some "unhashable" error. > > lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] > # how do i reduce this to > lsttwo = [ 1, 2, 3, 4, 5, 6 ] If t

Re: Filtering a Python list to uniques

2008-03-25 Thread Mensanator
On Mar 25, 6:30 pm, kellygreer1 <[EMAIL PROTECTED]> wrote: > What is the best way to filter a Python list to its unique members? > I tried some method using Set but got some "unhashable" error. > > lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] > # how do i reduce this to > lsttwo = [ 1, 2, 3, 4, 5, 6 ] > > I

Re: Filtering a Python list to uniques

2008-03-25 Thread Furkan Kuru
set(lstone) works fine in python 2.5.1 Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] >>> set(lstone) set([1, 2, 3, 4, 5, 6]) On 3/26/08, kellygr

Re: Filtering a Python list to uniques

2008-03-25 Thread bearophileHUGS
Kelly Greer: > What is the best way to filter a Python list to its unique members? If Python is "batteries included", then an industrial-strength unique() seems one of the most requested 'batteries' that's not included :-) I feel that it's coming in Python 2.6/3.x. In the meantime: http://aspn.act

Filtering a Python list to uniques

2008-03-25 Thread kellygreer1
What is the best way to filter a Python list to its unique members? I tried some method using Set but got some "unhashable" error. lstone = [ 1, 2, 3, 3, 4, 5, 5, 6 ] # how do i reduce this to lsttwo = [ 1, 2, 3, 4, 5, 6 ] Is there a page on this in the Python in a Nutshell or the Python Cookbook