-7

Here is my code

def getNegativesList(postivesAndNegativeslist):
        if postivesAndNegativeslist = None:
            return None
        elif len(postivesAndNegativeslist) = 0:
            return None
        negativesList = []
        for val in negativesList:
            if val<0:
                return negativesList.append(val)
print(getNegativesList(2,-3,-5,10,-1)
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
Spoo30
  • 3
  • 3
  • please include the error stack, thanks – glls Jun 04 '16 at 06:06
  • @glls it says its a ParseError and invalid syntax – Spoo30 Jun 04 '16 at 06:09
  • 4
    Literally almost the exact duplicate of http://stackoverflow.com/questions/37626234/return-negative-integers-from-a-list-in-python#comment62734818_37626234 Please edit according to the reasons why the similar question was put on-hold. – Moon Cheesez Jun 04 '16 at 06:09
  • 4
    @Spoo30, no it doesn't. It says more than that. You need to 1.) Read the entire message (learning to debug based on that will help you in the future) and 2.) Post the entire message here if you want more help. We aren't here to guess what your stack trace says. – Andy Jun 04 '16 at 06:12
  • @Spoo30 reposting a question will not get it answered. So far you are -10. – Merlin Jun 04 '16 at 06:22
  • 1
    @Rahul K P: Should be `is None` not `==None`. Testing equality with None doesn't do what most folk think it does. For reasons see http://stackoverflow.com/questions/26595/is-there-any-difference-between-foo-is-none-and-foo-none. Pep8 recommends against it for the reason given. –  Jun 04 '16 at 07:29
  • @gecko You are right. I deleted my comment. – Rahul K P Jun 04 '16 at 07:38

1 Answers1

-1

The code does not require explanation.

def getNegativesList(postivesAndNegativeslist):
    if postivesAndNegativeslist is None:
        return None
    elif len(postivesAndNegativeslist) == 0:
        return None
    negativesList = []
    for val in postivesAndNegativeslist:
        if val<0:
            negativesList.append(val)
    return negativesList
print(getNegativesList([2,-3,-5,10,-1]))
Sushant
  • 324
  • 2
  • 14
  • `if postivesAndNegativeslist is None:` **is** generally preferred. `None` is a single object which has many references to it. You don't make a variable equal to `None`, you make it *refer* to `None`. – cdarke Jun 04 '16 at 06:29
  • 2
    Have a read at http://meta.stackoverflow.com/a/316783/4428725 "If we want to encourage high-quality questions, there are better ways to do it. Namely, closing and not answering the low-quality ones." – Moon Cheesez Jun 04 '16 at 06:45
  • @cdarke Thanks for pointing it out. Editing it now – Sushant Jun 04 '16 at 07:10
  • @MoonCheesez Thanks for letting me know. Will keep that in mind next time before I answer a question. – Sushant Jun 04 '16 at 07:11
  • 2
    You should always try to explain what was wrong in the original code and how your answer fixes it, rather than just posting a bunch of code and expecting all readers to compare it with the original. – Barmar Jun 04 '16 at 07:11
  • @Barmar I would normally do it, but in this case I thought that the code was simple and self explanatory. And since the OP directly threw the question at us, I thought it would be better to just throw the answer back. – Sushant Jun 04 '16 at 07:16