I have a pretty simple Python script/task where I'm trying to search for a string of text while iterating over a list.
domains = ['google.com', 'facebook.com', 'cnn.com']
domain = []
for x in domains:
if any("google"):
domain.append("Google")
The output of the code above is: ['Google', 'Google', 'Google'] I'm expecting the output to just have one entry of "Google" since there is only one domain that would match.
I've tried
re.search('google',x)
and:
for x in domains:
if any("google" in x for x in domains):
domain.append("Google")
The output for each is the same. As long as there is an entry of "Google" in the entire list then each append entry will be "Google". I apologize as I'm sure this is a simple question but I can't quite seem to get it correctly. This is the last piece of my project and I'm stumped. Any help is appreciated.