at_the_party = ['bob', 'steve', 'james', 'alfred']
invited_list = ['Mr. bob', 'david', 'james']
First, how do i simply pass the item itterable into re.search, like below?
for item in at_the_party:
if re.search(item, invited_list):
print(item, " showed up to the party")
else:
print("didnt show up: ", item)
this gives me a generic 'type error'. I would expect to get back the following output:
james
Secondly, I want (i think i need to) pass the variable as what i guess is called string formatting with %s like such:
at_the_party = ['bob', 'steve', 'james', 'alfred']
invited_list = ['Mr. bob', 'david', 'james']
for item in at_the_party:
if re.search('.*%s.*' %item, invited_list):
print(item, " showed up to the party")
else:
print("didnt show up: ", item)
Is this the correct way to preform a re.search with a variable passed as both the pattern and string?