Ad
  • Custom User Avatar

    Bro this literally defeats the purpose ://

  • Custom User Avatar

    I already see one flaw right away. For this piece of code, you do not need to put 'if len(numbers) < 0:return numbers' because the for loop will not be activated by an empty list, and it will just simply skip it.

    Another one is that the if statements in the for loop are repetitive. There, you will see that no matter where the number goes in the if statement, if will always be multiplied by -1. So, you may simply state: 'for i in numbers: opposite_list.append(i * -1)' which saves much time since the computer still needs to check for a condition.

    Last one. If you don't know list comprehensions, you may search it up. It is really useful for this problem. Since you are iterating through the list with just one line of code inside the loop, you may simply do: 'return [i * -1 for i in numbers]' and that is it.

    So hope you learned something, bye!

  • Custom User Avatar

    Wow, never actually thought of it like that. I am ashamed of my solution now...