0
How do u return a list that contains elements that are similar in both list
a=[1,3,4,5,6] b=[1,4,5]
2 Réponses
+ 7
As an alternative to the provided solution from NotAPythonNinja you could use:
c = list(set(a) & set(b))
+ 6
2 perfect answers are already show, but i want to add a for loop. May be it helps for better understanding.
a=[1,3,4,5,6]
b=[1,4,5]
c = []
for num in a:
if num in b:
c.append(num)
print(c)