<div class="gmail_quote">On Fri, May 18, 2012 at 6:24 AM, Jorge Vargas <span dir="ltr">&lt;<a href="mailto:jorge.vargas@gmail.com" target="_blank">jorge.vargas@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Thank you all for the answers.<br>
<br>
This got me thinking about my dataset<br>
- The order is irrelevant, however it&#39;s good to have.<br>
- There should be only one of each type but it is not really enforced.<br>
Most checks here are in the for of &quot;value in states&quot; so if someone<br>
makes the mistake of adding the same state twice it doesn&#39;t really<br>
affect things.<br>
<br>
So a set seems to be the proper construction here. That said I could<br>
stick with a list as there is no real need of the overhead of sets (I<br>
know it&#39;s little) but it&#39;s really irrelevant to keep it as the only<br>
case where the list will contain the same value twice is by programmer<br>
error. So i believe the sorted(list) solution makes the most sense. It<br>
will catch errors as a state not being &quot;declared&quot; (that&#39;s what the<br>
decorator does), catch if the same state is added twice but will not<br>
really care about the order.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>See also assertItemsEqual (renamed to assertCountEqual in 3.2).</div><div><br></div><div> <a href="http://docs.python.org/library/unittest.html#unittest.TestCase.assertItemsEqual">http://docs.python.org/library/unittest.html#unittest.TestCase.assertItemsEqual</a></div>

<div> <a href="http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertCountEqual">http://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertCountEqual</a></div><div><br></div><div>-gps</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
On Thu, May 17, 2012 at 7:16 PM, Andrew Dalke &lt;<a href="mailto:dalke@dalkescientific.com">dalke@dalkescientific.com</a>&gt; wrote:<br>
&gt; On May 17, 2012, at 3:30 AM, Jorge Vargas wrote:<br>
&gt;&gt; My question is which will be the proper way to test for this when the<br>
&gt;&gt; &quot;order of the list&quot; is not valid?<br>
&gt;<br>
&gt; The right answer depends on what the data set contains. Others have<br>
&gt; already suggested:<br>
&gt;<br>
&gt;  1) sorting; but that assumes that the objects can be compared<br>
&gt;      by inequality<br>
&gt;<br>
&gt;  2) converting to a set, but that assumes that objects are hashable,<br>
&gt;      and that duplicates can be ignored<br>
&gt;<br>
&gt; You can fix #2 by<br>
&gt;<br>
&gt;  3) use a collections.Counter; this still requires hashable objects<br>
&gt;       but doesn&#39;t have the count problem<br>
&gt;<br>
&gt;<br>
&gt; The only generic solution is:<br>
&gt;<br>
&gt;  4) Do the O(n*m) test of checking each item from one list to see<br>
&gt;       if it occurs in the other, removing matches as they are found<br>
&gt;<br>
&gt; Most people are uncomfortable with potentially quadratic worst-case<br>
&gt; times, but with only a couple of states, this isn&#39;t a problem.<br>
&gt;<br>
&gt;<br>
&gt; In your case, you can probably use the sets solution without a problem,<br>
&gt; especially if your &quot;next&quot; implementation verifies that there are no<br>
&gt; duplicates in the list. Or as Herman&#39;s commented, perhaps your<br>
&gt; implementation is more appropriate with a set in the first place?<br>
&gt;<br>
&gt; Cheers,<br>
&gt;<br>
&gt;                                Andrew<br>
&gt;                                <a href="mailto:dalke@dalkescientific.com">dalke@dalkescientific.com</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</div></div></blockquote></div><br>