>>> a = {1, 2, 3}
>>> b = {2, 3, 4}
>>> a & b
{2, 3}
On Wednesday, 26 January 2022 at 23:52:05 UTC+11 xaadx...@gmail.com wrote:
> a = [1,2,3,4]
> b = [3,4,5,6]
>
> Convert list a to set
> a_set = set(a)
> print(a_set.intersection(b))
>
> On Wed, Jan 26, 2022, 5:47 PM Muhammad Shehzad wrote:
>
>>
a = [1,2,3,4]
b = [3,4,5,6]
Convert list a to set
a_set = set(a)
print(a_set.intersection(b))
On Wed, Jan 26, 2022, 5:47 PM Muhammad Shehzad
wrote:
> Use intersection
>
> On Wed, Jan 26, 2022, 4:06 PM bnmng wrote:
>
>> Thank you. I think I'll go with sets as advised, although this method
>> a
Use intersection
On Wed, Jan 26, 2022, 4:06 PM bnmng wrote:
> Thank you. I think I'll go with sets as advised, although this method
> also looks very neat:
> intersection = [item for item in list1 if item in list2] found at
> https://datagy.io/python-intersection-between-lists/
>
>
>
>
> On Tue
Thank you. I think I'll go with sets as advised, although this method also
looks very neat:
intersection = [item for item in list1 if item in list2] found at
https://datagy.io/python-intersection-between-lists/
On Tuesday, January 25, 2022 at 3:11:10 PM UTC-5 joezep...@gmail.com wrote:
You can use sets
On Tue, Jan 25, 2022 at 7:47 AM bnmng wrote:
> Hello,
>
> Is there a built in function that compares two or more lists and returns
> elements common to all?
>
> like this:
>
> def in_both( list_a, list_b ):
> list_c=[]
> for value in list_a:
> if value in list_b:
> list_c.append
Thank you. That set.intersection with list conversion seems like the way
to go. On your second point, well taken. I'll keep that in mind for
future Python questions
On Tuesday, January 25, 2022 at 7:46:58 AM UTC-5 bnmng wrote:
> Hello,
>
> Is there a built in function that compares two or mo
On 25/01/2022 13.46, bnmng wrote:
Hello,
Is there a built in function that compares two or more lists and returns
elements common to all?
The intersect member function almost does that, just combine in with
converting your list to a set:
https://datagy.io/python-intersection-between-list
Hello,
Is there a built in function that compares two or more lists and returns
elements common to all?
like this:
def in_both( list_a, list_b ):
list_c=[]
for value in list_a:
if value in list_b:
list_c.append(value)
return list_c
Or this:
def in_all(list_of_lists):
list_a = list_of_lists.po
8 matches
Mail list logo