Guest User

Untitled

a guest
Jun 18th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #lab 1.3
  2.  
  3. # combo toolkit allows easy coding combinations, found after spending hours trying to
  4. # hard code if statements, this is way easier
  5. from itertools import combinations
  6.  
  7. # itertools uses the combinations to iterate through and find matches ([index], choose 3)
  8. input_int = list(combinations([1, 3, 6, 2, -1, 2, 8, -2, 9], 3))
  9.  
  10. # variables, and index for parsing through the input_int
  11. triplets = []
  12. ind = 0
  13. length = len(input_int)
  14.  
  15. # for loop iterates through index, sum(input_int[ind]) == 0 stops when it finds a
  16. # three integer combonation with a total sum of zero
  17. for i in range(length):
  18. if sum(input_int[ind]) == 0:
  19. triplets.append(input_int[ind])
  20. ind += 1
  21.  
  22. print("The following triplets have sum zero: ", triplets)
Add Comment
Please, Sign In to add comment