Skip to content

Instantly share code, notes, and snippets.

@mahanmarwat
Last active October 27, 2015 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahanmarwat/5ea976bdd1985106a912 to your computer and use it in GitHub Desktop.
Save mahanmarwat/5ea976bdd1985106a912 to your computer and use it in GitHub Desktop.
Search for user input in a list of lines (created from file).
def find_match(keys_file, values_file, user_input):
keys = []
values = []
with open(keys_file) as k_handler, open(values_file) as v_handler:
keys = [line.rstrip('\n') for line in k_handler]
values = [line.rstrip('\n') for line in v_handler]
is_found = False
if keys and values:
try:
# insure keys are lowercase.
is_found = values[keys.index(user_input.lower())]
except ValueError:
pass
return is_found
# find_match('keys.txt', 'values.txt', 'who')
# 'I am Artha.'
# find_match('keys.txt', 'values.txt', 'hi')
# 'Hi, you.'
@zealsham
Copy link

I get it now adnan khan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment