On 6 April 2013 05:58, Darth Pookie <darthpooki...@gmail.com> wrote: > Hello, > > I am generating two lists that represent ordered pairs. I have three lists > called j,k,l, from which I make my ordered pairs. Let's say I have one list > of pairs (lets call it list1) that is made up of j and k. I have another > list of pairs (lets call it list2) that is made up of j and l. Both lists > are created using zip (i.e. list1=zip(j,k). I want to compare the values of > k and l in both lists, and when I find a match, print the associated j's from > each list. I am at a loss as to how to compare members of lists, other than > determining if two lists are equal. > > In C/C++ I might iterate through an array of values in the first list and > compare each to the first value in the second list, than increment the > element of the second array and do it all over again, until I find a match. > However I would think there was a better way to do this in sage/python? >
Try [j for (j,k),(j1,l) in zip(list1,list2) if j1==j] or perhaps that should be [(j1,j2) for (j1,k),(j2,l) in zip(list1,list2) if k==l] John Cremona > Any thoughts are appreciated. > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-support?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support?hl=en. For more options, visit https://groups.google.com/groups/opt_out.