Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying common element in list in python

Tags:

python

I have two lists. I need to compare elements whether any element in the list is matching or not. Input:

a = ['1001,1715']
b = ['1009,1715']

Output : 1715

Please suggest how to do it? I tried doing:

set(''.join(a))

and

set(''.join(b)) 

but it gave me {'5', '0', '7', ',', '1'}. how can I convert ['1001,1715'] to [1001,1715] ?

like image 324
Kumar Pushkar Avatar asked Jan 24 '26 12:01

Kumar Pushkar


1 Answers

a = ['1001,1715']
b = ['1009,1715']

def fun(a):
  return a[0].split(",")

def intersect(a, b):
  return list(set(a) & set(b))

print(intersect(fun(a),fun(b)))
like image 108
Naor Tedgi Avatar answered Jan 27 '26 02:01

Naor Tedgi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!