Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """return the product of all ints in a list except the current index"""
- def get_products(values):
- """relies on range and len to produce an index"""
- output = []
- for i in range(len(values)):
- lst = []
- for value in values:
- if value == values[i]:
- pass
- else:
- lst.append(value)
- output.append(reduce(lambda x, y: x*y, lst))
- return output
- print get_products([1, 7, 3, 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement