samedi 14 avril 2018

Using a Dictionary To Search inside a String

So, lets say I have the following:

String = "A"

if String in {"A", "B", "C"}:
    print("True")

else:
    print("False")

Now this should definitely print the string "True".

Okay, now lets say we change it such that:

String = "ABCD"

My goal from this point is to use the same set from before but this time return "True" if any of the values are inside of the string given.

My idea:

String = "ABCD"

if {"A", "B", "C"} in String:
        print("True")

    else:
        print("False")

I tried this and it did not work.

I believe I could do this with a lot of if Statements, however I am hoping there's a way around that.

What would be the best way of accomplishing what I want to do?

Aucun commentaire:

Enregistrer un commentaire