Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #!/usr/bin/python
  2. """return the product of all ints in a list except the current index"""
  3.  
  4. def get_products(values):
  5. """relies on range and len to produce an index"""
  6. output = []
  7.  
  8. for i in range(len(values)):
  9. lst = []
  10. for value in values:
  11. if value == values[i]:
  12. pass
  13. else:
  14. lst.append(value)
  15.  
  16. output.append(reduce(lambda x, y: x*y, lst))
  17.  
  18. return output
  19.  
  20. print get_products([1, 7, 3, 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement