Skip to content

Instantly share code, notes, and snippets.

@glipR
Created June 25, 2018 07:05
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 glipR/94f0ca2863b28fd42261db637f5ad7d3 to your computer and use it in GitHub Desktop.
Save glipR/94f0ca2863b28fd42261db637f5ad7d3 to your computer and use it in GitHub Desktop.
target = int(input())
# Pull the list from input, split by ", " character, and convert to integers
pair_list = list(map(int, input().split(", ")))
# Create a set (all unique elements from the list)
pair_set = set(pair_list)
results = []
for item1 in pair_set:
for item2 in pair_set:
# Only one of each pair, so force them ascending
if item1 <= item2:
# If they meet the criteria
if item1+item2 = target:
if item1 != item2:
results.append((item1, item2))
else:
# Make sure that we have more than one element to make a pair
if pair_list.count(item1) > 1:
results.append((item1, item2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment