HOME/Articles/

python code find element exists two lists (snippet)

Article Outline

Python example 'python code find element exists two lists'

Functions in program:

  • def union(a,b):

python code find element exists two lists

Python code example: python code find element exists two lists


#Find elements that exist in either of the two lists

def union(a,b):
    return list(set(a + b))
union([1, 2, 3, 4, 5], [6, 2, 8, 1, 4])

More Python: https://pythonprogramminglanguage.com