-1

How to check a value in the list is not equal. Want to check the values that are in the list. between two items, for example, if listA does not have any of the same items as in listB removing that item

listA = [0, 1, 2, 3]
listB = [2, 3]

Result = [2, 3]
  • 1
    Your question is not clear: "the index value of that value" suggests you look for indices, not items. You should replace 0,1,2,3 by 'a', 'b', 'c', 'd' to clarify – Demi-Lune Jun 02 '21 at 11:43
  • Probable solutions can be found in [fastest-way-to-check-if-a-value-exists-in-a-list](https://stackoverflow.com/questions/7571635/fastest-way-to-check-if-a-value-exists-in-a-list) and about 20-30 other posts concerning themselfs with finding things in lists with python. What did you code, [mre] what went wrong? What did you find on SO relating to your problem, why did it not help? If you need to do so for multiple things, loop over them or use a list comprehension – Patrick Artner Jun 02 '21 at 11:45

2 Answers2

0

try it...

listA = [0, 1, 2, 3]
listB = [2, 3]
result = [i for i in listA if i in listB]
print(result)
PrA-patel
  • 99
  • 1
  • 2
0

result = list(set(listA).intersection(set(listB)))

use set intersection https://www.w3schools.com/python/ref_set_intersection.asp

nilay shah
  • 61
  • 3