I have two lists: total_price and units_b, which both contain null values and I have an expression to divide total_price by units_b:
total_price = [None, None, 10, 20]
units_b = [None, None, 1, 2]
average_price = [(x/y) for x, y in zip(total_price, units_b)]
Trying to run average_price gives me an error saying that I can’t divide two ‘NoneTypes’. Is there any way that I can exclude the null values for the division but perserve the integrity of the original list?
1 Answer