So I have a list of names
name_list = [\"John Smith\", \"John Wrinkle\", \"John Wayne\", \"David John\", \"David Wrinkle\", \"David Wayne\"]
I
Change your matches
to:
matches = [name for name in name_list if name.startswith(search)]
You can also make some changes to your code:
# You can do this in one go
search = input(str("Search: ")).lower()
# Why bother looping if search string wasn't provided.
if not search:
print("Empty search field")
else:
# This can be a generator
for i in (name for name in name_list if name.startswith(search)):
print(i.title())