test for list equality
darnold
darnold992000 at yahoo.com
Thu Dec 15 13:12:39 EST 2011
On Dec 15, 11:59 am, Miki Tebeka <miki.teb... at gmail.com> 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)
I'm pretty sure we don't want to use set() since it throws away
duplicates:
>>> x = [1,2,3,4]
>>> y = [1,1,2,2,3,3,4]
>>> sorted(x) == sorted(y)
False
>>> set(x) == set(y)
True
More information about the Python-list
mailing list