Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

check any of value from a list is equal to any of value from other list python code for…

  1. User

    check any of value from a list is equal to any of value from other list python code for that

  2. Assistant

    You can use the any() function to check if any element from one list is equal to any element from another list. Here's an example:

    list1 = [1, 2, 3, 4, 5]
    list2 = [5, 6, 7, 8, 9]
    
    # Check if any element from list1 is equal to any element from list2
    if any(x == y for x in list1 for y in list2):
        print("There is a common value.")
    else:
        print("There is no common value.")
    

    Output:

    There is a common value.
    

    In this example, the any() function evaluates if any combination of x from list1 and y from list2 satisfies the condition x == y. If at least one pair of elements is equal, it returns True, otherwise False.