Last active
October 27, 2015 10:20
-
-
Save mahanmarwat/5ea976bdd1985106a912 to your computer and use it in GitHub Desktop.
Search for user input in a list of lines (created from file).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get it now adnan khan