Search code examples
pythonstringlistcompare

Checking for 2 different strings in the same list


What I mean by that is, that I want to take a list, let's say"

["i","am","you","pure","fact"], 

then check whether this list contains 2 different strings, like "i" and "pure", and then if true, it runs something. This is what I am looking for, but in PYTHON. I don't know how to do this sort of check.


Solution

  • Try this out

    elements: list = ["i","am","you","pure","fact"]
    str1: str = "i"
    str2: str = "pure"
    
    if str1 in elements and str2 in elements:
        # Execute code
        ...