git-subtree-dir: users/wpcarro git-subtree-mainline:464bbcb15cgit-subtree-split:24f5a642afChange-Id: I6105b3762b79126b3488359c95978cadb3efa789
		
			
				
	
	
		
			19 lines
		
	
	
	
		
			472 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
	
		
			472 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import random
 | |
| 
 | |
| def find_pairs(xs, n):
 | |
|     """
 | |
|     Return all pairs of integers in `xs` that sum to `n`.
 | |
|     """
 | |
|     seeking = set()
 | |
|     result = set()
 | |
|     for x in xs:
 | |
|         if x in seeking:
 | |
|             result.add((n - x, x))
 | |
|         else:
 | |
|             seeking.add(n - x)
 | |
|     return result
 | |
| 
 | |
| xs = [random.randint(1, 10) for _ in range(10)]
 | |
| n = random.randint(1, 10) + random.randint(1, 10)
 | |
| print("Seeking all pairs in {} for {}...".format(xs, n))
 | |
| print(find_pairs(xs, n))
 |