Thanks Michael, this worked great, time to read up on collections!<br><br><div class="gmail_quote">On Jan 24, 2008 3:36 AM, Michael Langford &lt;<a href="mailto:mlangford.cs03@gtalumni.org">mlangford.cs03@gtalumni.org</a>&gt; wrote:
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">You use a variation on bucket sort do to this:<br><a href="http://en.wikipedia.org/wiki/Bucket_sort" target="_blank">
http://en.wikipedia.org/wiki/Bucket_sort</a><br><br>You make a dict where the keys are the values in the lists, and a name<br>for each list is in the problem.<br><br>So you get something that looks like:<br><br>one: list1, list2
<br>two: list1, list2, list3<br>etc<br><br>Doing this with collections.defaultdict is a breeze:<br>import collections<br><br>dd = collections.defaultdict(list)<br>for eachlist in lists:<br> &nbsp; for each in eachlist:<br> &nbsp; &nbsp; &nbsp; dd[each].append(getListName(eachlist))
<br><br>Then to find the repeated elements you filter &nbsp;where the list is of length &gt; 1.<br><br>for each in dd:<br> &nbsp; &nbsp; print &quot;%s: %s&quot; % (each, dd[each])<br><br>I&#39;d provide code, but I&#39;m not sure what an appropriate naming function
<br>is for you, nor am I sure what you&#39;re doing with this when you&#39;re<br>done.<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--Michael<br><div class="Ih2E3d"><br><br><br>On Jan 24, 2008 3:15 AM, Fiyawerx &lt;<a href="mailto:fiyawerx@gmail.com">
fiyawerx@gmail.com</a>&gt; wrote:<br>&gt; I have been able to find a few articles on comparing 2 lists, but I have 4<br>&gt; lists that I need to compare. I need to find any repeated elements and the<br>&gt; list that they came from. For example,
<br>&gt;<br>&gt; list1 = [&#39;one&#39;, &#39;two&#39;, &#39;three&#39;]<br>&gt; list2 = [&#39;one&#39;, &#39;two&#39;, &#39;four&#39;, &#39;five&#39;]<br>&gt; list3 = [&#39;two&#39;, &#39;three&#39;, &#39;six&#39;, &#39;seven&#39;]
<br>&gt; list4 = [&#39;three&#39;, &#39;five&#39;, &#39;six&#39;]<br></div>&gt; <a href="https://mail.google.com/mail/#label/Pythontutor/117aadf8364dbf3b" target="_blank">https://mail.google.com/mail/#label/Pythontutor/117aadf8364dbf3b
</a><br>Gmail - [Tutor] Comparing more than 2 lists - <a href="mailto:michael.langford@gmail.com">michael.langford@gmail.com</a><br><div class="Ih2E3d">&gt;<br>&gt; &nbsp;I need to be able to get along the lines of output:<br>
&gt; Element &#39;one&#39; contained in list1 and list2<br>&gt; Element &#39;two&#39; contained in list1 and list2 and list3<br>&gt; ...<br>&gt; Element &#39;five&#39; contained in list2 and list4<br>&gt;<br>&gt; etc.. and I can&#39;t quite figure out how to go about it
<br>&gt;<br>&gt;<br></div>&gt; _______________________________________________<br>&gt; Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br>&gt; <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">
http://mail.python.org/mailman/listinfo/tutor</a><br>&gt;<br>&gt;<br><font color="#888888"><br><br><br>--<br>Michael Langford<br>Phone: 404-386-0495<br>Consulting: <a href="http://www.RowdyLabs.com" target="_blank">http://www.RowdyLabs.com
</a><br></font></blockquote></div><br>