To check if a string is present in a dataset in Python, you can use the in
operator or the find()
method. Here's an example:
main.py385 chars15 lines
In the above code, the in
operator is used to check if the query
string is present in the dataset
list. If it is, it prints that the string is present; otherwise, it prints that the string is not present.
Alternatively, you can use the find()
method on the dataset string to check if the query string is present. The find()
method returns the index of the first occurrence of the query string in the dataset string. If the query string is not found, it returns -1.
Remember to replace dataset
with your actual dataset and query
with the string you want to check.
gistlibby LogSnag