test for list equality
Chris Kaynor
ckaynor at zindagigames.com
Thu Dec 15 13:04:01 EST 2011
On Thu, Dec 15, 2011 at 9:57 AM, John Gordon <gordon at panix.com> wrote:
> In <61edc02c-4f86-45ef-82a1-61c7013003b4 at t38g2000yqe.googlegroups.com>
> noydb <jenn.duerr at gmail.com> 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 .
>
And you cannot use the method in-line - it mutates the list in place,
returning None.
If you either do not wish to mutate the list, or you absolutely want to do
the sort in-line, you need to use the sorted built-in:
if sorted(x) == sorted(y):
...
However, this will, temporary, use double the memory.
>
> --
> John Gordon A is for Amy, who fell down the stairs
> gordon at panix.com B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111215/c8730b48/attachment-0001.html>
More information about the Python-list
mailing list