Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
The best way to check if two lists have identical values
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="mk, post: 4033467"] Hello everyone, I have stumbled upon this seemingly trivial problem: the answer is not there in [URL]http://www.python.org/doc/faq/programming/[/URL], and googling does not return many references really (at least for me). I have come up with this: def qips_identical(q, oldq): qips = map(operator.itemgetter(1), q) oldqips = map(operator.itemgetter(1), oldq) if len(qips) != len(oldqips): return False dif = set(qips) ^ set(oldqips) if len(dif): return False return True There's a number of complications here, depending on definition of 'lists with identical values', like whether the same value can be repeated different number of times in two lists, or whether the order of values matters. In above example I assumed that the same values have to be repeated the same numbers of times in both lists and that order doesn't matter so long as the values are the same. I was wondering if there's a better / shorter / faster way to do this -- not necessarily in the same variant, e.g. variant where order of two lists matters would be interesting as well. Regards, mk [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
The best way to check if two lists have identical values
Top