ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 05 Mar 2017 02:07:56 -0600Finding intersection of two lists?https://ask.sagemath.org/question/36829/finding-intersection-of-two-lists/Hello, guys. First of all, I'm very new to Sage and also to this forum, so please be generous for my question...
So, suppose we have
c=[[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4]],
d=[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4], [9, 8, 7, 6]]
I would like to get
[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4]]
which is intersection of c and d. Is there a way to do this?
Thank you for any help.Sat, 04 Mar 2017 14:48:54 -0600https://ask.sagemath.org/question/36829/finding-intersection-of-two-lists/Answer by FrédéricC for <p>Hello, guys. First of all, I'm very new to Sage and also to this forum, so please be generous for my question...</p>
<p>So, suppose we have</p>
<p>c=[[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 3, 4], [0, 2, 3, 4], [1, 2, 3, 4]],</p>
<p>d=[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4], [9, 8, 7, 6]]</p>
<p>I would like to get </p>
<p>[[0, 1, 2, 3], [0, 1, 3, 4], [0, 2, 3, 4]]</p>
<p>which is intersection of c and d. Is there a way to do this? </p>
<p>Thank you for any help.</p>
https://ask.sagemath.org/question/36829/finding-intersection-of-two-lists/?answer=36831#post-id-36831Like that:
[x for x in list0 if x in list1]Sun, 05 Mar 2017 02:07:56 -0600https://ask.sagemath.org/question/36829/finding-intersection-of-two-lists/?answer=36831#post-id-36831