Skip to content

Instantly share code, notes, and snippets.

@winniethemu
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save winniethemu/dd5e4a63769c62a347b3 to your computer and use it in GitHub Desktop.
Save winniethemu/dd5e4a63769c62a347b3 to your computer and use it in GitHub Desktop.
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