Last active
August 29, 2015 14:13
-
-
Save winniethemu/dd5e4a63769c62a347b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
# Use two blank lines since the methods are defined in | |
# the global scope. Otherwise use one. | |
def populate_list(input_lines): | |
for input_line in input_lines: | |
input_line = int(input_line) | |
values_list.append(input_line) | |
def populate_dict(): | |
for value in values_list: | |
values_dict[value] = True | |
def value_pair_exists(num): | |
for value in values_list: | |
if values_dict.get(num - value): | |
return True | |
return False | |
# Global variables should be avoided when they could | |
# potentially be updated by different methods. | |
# Here it actually saves us the trouble of passing it | |
# around, therefore makes our code simpler. | |
values_dict = {} | |
values_list = [] | |
numbers = sys.argv[1:] | |
lines = open('data', 'r').read().splitlines() | |
populate_list(lines) | |
populate_dict() | |
for number in numbers: | |
number = int(number) | |
print value_pair_exists(number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment