Hi,
I came up with this solution for challenge 4 (list of products of all elements), it works but not sure if it is good. Could you give me feedback, Thanks!
def find_product(lst):
p = 1
result = []
num_zeros = lst.count(0)
for i in range(len(lst)):
if lst[i] != 0:
p *= lst[i]
for j in range(len(lst)):
if 0 in lst:
if num_zeros > 1:
result.append(0)
elif lst[j] == 0:
result.append(p)
else:
result.append(0)
else:
result.append(p / lst[j])
return result
Type your question above this line.
Course: https://www.educative.io/collection/5642554087309312/5634727314718720
Lesson: https://www.educative.io/collection/page/5642554087309312/5634727314718720/5759700863811584