Help needed please - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help needed please (/thread-11158.html) |
Help needed please - mattick - Jun-25-2018 Hi all, hoping someone can help me. I have an array that finds the range in difference between highest and lowest positive integers. I can accomplish this bit, however if a negative integer(s) is inserted within the array. I need to find a way that the negative integers aren't included in the output? daily_sales = [-5, 8, 12, 23, 7, 56, 99, 65] lowest = min(daily_sales) highest = max(daily_sales) negative = 0 if x in range(len([daily_sales])) < 1: print() else: difference = highest - lowest print(difference) RE: Help needed please - gontajones - Jun-25-2018 I'm not sure if I got the idea, but if you want to remove the negative numbers from a list: daily_sales = [x for x in daily_sales if x >= 0] RE: Help needed please - Gribouillis - Jun-25-2018 You can simply remove the negative sales sales = [x for x in daily_sales if x >= 1] RE: Help needed please - mattick - Jun-26-2018 Thank you for your help, solution to problem is solved. |