Hi,<br><br>a = [4,3,2,6,7,9]<br>b = [8,6,3,3,2,7]<br><br>You can turn this into a list of two element tuples with zip():<br>>>> zip(a,b)<br>[ (4,8),(3,6,),(2,3),(6,3),(7,2),(9,7) ]<br><br>Now you can loop through that and compare both elements, for instance I believe this list comprehension is what you're looking for:
<br><br>[ t[0] < t[1] for t in zip(a,b) ]<br><br>but of course we can write that more elegantly with<br><br>[ i<j for i,j in zip(a,b) ]<br><br>Gives a list of booleans.<br><br>Remco Gerlich<br><br><div class="gmail_quote">
On Dec 25, 2007 4:52 PM, sith . <<a href="mailto:sith618@yahoo.com">sith618@yahoo.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>sith . wrote:<br>> Hi,<br>> I've read the posts on comparing 2 lists and couldn't find the answer to<br>> my question.<br>> I have 2 lists<br>> a = [4,3,2,6,7,9]<br>> b = [8,6,3,3,2,7]<br>> How can I determine if the elements in a are larger or smaller than the
<br>> elements in b.<br>> <br>> for i in a:<br>> for u in b:<br>> i > u<br>> does not return the result I seek.<br>> <br>> In this example, 4 from a is compared to 8,6,3,3,2,7 then 3 from a is
<br>> compared to all the elements in b.<br>> I'd like<br>> 4 to 8,<br>> 3 to 6,<br>> 2 to 3 and so on; like 2 columns in excel, the third column would be a<br>> new list of boolean values.<br>> Can someone help please? Thank you.
<br>> </div> <div>all(all(i>j for j in b) for i in a)</div> <div>HTH</div> <div> </div> <div> </div> <div>Hi,<br>Thanks for
your reply. This is what I get:</div> <div>>>> a = [4,3,2,6,7,9]</div> <div>>>> b = [8,6,3,3,2,7]</div> <div>>>> all(all(i>j for j in b) for i in a)<br>>>> all(all(i>j for j in b) for i in a)
</div> <div>False</div> <div>How do I make it loop through the whole list?</div><div class="WgoR0d"><p>
</p><hr size="1">Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs" target="_blank"> Make Yahoo your homepage.</a>
</div><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor
</a><br><br></blockquote></div><br>