# Find pairs in a list that sum up to a given target k.
def find_pairs(l, k):
toret = []
for i, x in enumerate(l):
if x <= k:
target = k - x
if target in l[i + 1:]:
toret.append((x, target))
# break
return toret
if __name__ == "__main__":
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(l, "@", 3, " =", find_pairs(l, 3))
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(l, "@", 8, " =", find_pairs(l, 8))
l = [14, 7, 3, 4]
print(l, "@", 7, " =", find_pairs(l, 7))
l = [14, 7, 7, 4]
print(l, "@", 14, " =", find_pairs(l, 14))
l = [14, 7, 0, 4]
print(l, "@", 7, " =", find_pairs(l, 7))
l = [4, 14, 3, 2, 7]
print(l, "@", 7, " =", find_pairs(l, 7))
IyBGaW5kIHBhaXJzIGluIGEgbGlzdCB0aGF0IHN1bSB1cCB0byBhIGdpdmVuIHRhcmdldCBrLgoKZGVmIGZpbmRfcGFpcnMobCwgayk6Cgl0b3JldCA9IFtdCgkKCWZvciBpLCB4IGluIGVudW1lcmF0ZShsKToKCQlpZiB4IDw9IGs6CgkJCXRhcmdldCA9IGsgLSB4CgoJCQlpZiB0YXJnZXQgaW4gbFtpICsgMTpdOgoJCQkJdG9yZXQuYXBwZW5kKCh4LCB0YXJnZXQpKQoJCQkJIyBicmVhawoJCglyZXR1cm4gdG9yZXQKCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgoJbCA9IFsxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5LCAxMF0KCXByaW50KGwsICJAIiwgMywgIiA9IiwgZmluZF9wYWlycyhsLCAzKSkKCglsID0gWzEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDksIDEwXQoJcHJpbnQobCwgIkAiLCA4LCAiID0iLCBmaW5kX3BhaXJzKGwsIDgpKQoJCglsID0gWzE0LCA3LCAzLCA0XQoJcHJpbnQobCwgIkAiLCA3LCAiID0iLCBmaW5kX3BhaXJzKGwsIDcpKQoJCglsID0gWzE0LCA3LCA3LCA0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