Re: test for list equality

2011-12-15 Thread Ian Kelly
On Fri, Dec 16, 2011 at 12:11 AM, Ian Kelly wrote: > On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor wrote: >> Just for fun, use the Hungarian Algorithm >> >> (Python implementation: http://software.clapper.org/munkres/) > > That's a pretty silly approach, but okay: > > def listequals(a, b): >    i

Re: test for list equality

2011-12-15 Thread Ian Kelly
On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor wrote: > Just for fun, use the Hungarian Algorithm > > (Python implementation: http://software.clapper.org/munkres/) That's a pretty silly approach, but okay: def listequals(a, b): if len(a) != len(b): return False matrix = [[int(item

Re: test for list equality

2011-12-15 Thread Alec Taylor
Just for fun, use the Hungarian Algorithm (Python implementation: http://software.clapper.org/munkres/) On Fri, Dec 16, 2011 at 3:36 AM, noydb wrote: > I want to test for equality between two lists.  For example, if I have > two lists that are equal in content but not in order, I want a return >

Re: test for list equality

2011-12-15 Thread Terry Reedy
On 12/15/2011 12:59 PM, Miki Tebeka wrote: My sort issue... as in this doesn't work if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) or x.sort

Re: test for list equality

2011-12-15 Thread Ian Kelly
On Thu, Dec 15, 2011 at 11:07 AM, noydb wrote: > Ahh, I see (on the sort issue), thanks All! > > Still, any other slicker ways to do this?  Just for learning. MRAB's collections.Counter suggestion is what I would do. Very tidy, and also more efficient I think: O(n) instead of O(n log n). -- htt

Re: test for list equality

2011-12-15 Thread Miki Tebeka
> > set(x) == set(y) > > Duplicates cause issues in the set() version: You're right, I stand corrected. -- http://mail.python.org/mailman/listinfo/python-list

Re: test for list equality

2011-12-15 Thread Tim Chase
On 12/15/11 11:59, Miki Tebeka wrote: My sort issue... as in this doesn't work if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) Duplicates cau

Re: test for list equality

2011-12-15 Thread MRAB
On 15/12/2011 17:59, Miki Tebeka wrote: My sort issue... as in this doesn't work >>> if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) But do

Re: test for list equality

2011-12-15 Thread MRAB
On 15/12/2011 17:49, noydb wrote: On Dec 15, 11:36 am, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that e

Re: test for list equality

2011-12-15 Thread darnold
On Dec 15, 11:59 am, Miki Tebeka wrote: > > My sort issue... as in this doesn't work > > >>> if x.sort == y.sort: > > You're missing the () to make it a function call. > Also list.sort() returns none, it mutates the original list. > You can either >     sorted(x) == sorted(y) > or >     set(x) ==

Re: test for list equality

2011-12-15 Thread noydb
Ahh, I see (on the sort issue), thanks All! Still, any other slicker ways to do this? Just for learning. -- http://mail.python.org/mailman/listinfo/python-list

Re: test for list equality

2011-12-15 Thread Chris Kaynor
On Thu, Dec 15, 2011 at 9:57 AM, John Gordon wrote: > In <61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com> > noydb writes: > > > My sort issue... as in this doesn't work > > >>> if x.sort =3D=3D y.sort: > > ... print 'equal' > > ... else: > > ... print 'not equal' > > ... >

Re: test for list equality

2011-12-15 Thread Miki Tebeka
> My sort issue... as in this doesn't work > >>> if x.sort == y.sort: You're missing the () to make it a function call. Also list.sort() returns none, it mutates the original list. You can either sorted(x) == sorted(y) or set(x) == set(y) -- http://mail.python.org/mailman/listinfo/python-l

Re: test for list equality

2011-12-15 Thread Stefan Behnel
noydb, 15.12.2011 18:49: On Dec 15, 11:36 am, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would

Re: test for list equality

2011-12-15 Thread John Gordon
In <61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com> noydb writes: > My sort issue... as in this doesn't work > >>> if x.sort =3D=3D y.sort: > ... print 'equal' > ... else: > ... print 'not equal' > ... > not equal > ??? Use x.sort() instead of x.sort . -- John Gordon

Re: test for list equality

2011-12-15 Thread MRAB
On 15/12/2011 16:36, noydb wrote: I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists

Re: test for list equality

2011-12-15 Thread noydb
On Dec 15, 11:36 am, noydb wrote: > I want to test for equality between two lists.  For example, if I have > two lists that are equal in content but not in order, I want a return > of 'equal' -- dont care if they are not in the same order.  In order > to get that equality, would I have to sort bot

test for list equality

2011-12-15 Thread noydb
I want to test for equality between two lists. For example, if I have two lists that are equal in content but not in order, I want a return of 'equal' -- dont care if they are not in the same order. In order to get that equality, would I have to sort both lists regardless? if yes, how (having is