Quantcast
Viewing all articles
Browse latest Browse all 210

Getting a return value of None when it works in all other situations in a function with parameters, variables, lists, etc [duplicate]

# Sample Codeimport datetimesample = {"Eat": [        datetime.datetime(2024, 9, 13, 2, 0),        datetime.datetime(2024, 9, 13, 3, 0),"2024-09-13 20:43:35.440898",    ],"Sleep": [        datetime.datetime(2024, 9, 13, 4, 0),        datetime.datetime(2024, 9, 13, 20, 0),"2024-09-13 20:43:24.354440",    ],}# This is the entire function that I am usingdef SortObjectives(obj):    temLis = []    temDic = {}    for i in obj:        print(str(obj[i][0].time()))        temLis.append(obj[i][0].time())    temLis.sort()    print(temLis)    temCou = 0    # Recursive Function    def SortObjectivesR(count):        for i in obj:            print(count)            print(str(temLis[count]) +" --From temLis)")            if obj[i][0].time() == temLis[count]:                temDic[i] = obj[i]                print(len(temDic))                print(len(obj))                if len(temDic) == len(obj):                    print("Here")                    print(temDic)                    return temDic                    # Why does this return None when it has a literal value???                    # Keep in mind that this function only does this when their are two items                    # in the obj dictionary when their not in order                    # It works when in order and when in the number of items is > or < then 2                else:                    count += 1                    SortObjectivesR(count)                    # return temDic - not part of original code    print(SortObjectivesR(temCou))    # How I find what it returns    # Would put in return statement to save lines, but it returns None    # Under the specific condition mentioned, the alteration of    # Variables work just fine.    return temDicprint(SortObjectives(sample))

I have tried changing the order of the items and number of items and testing it to see if it would recreate the issue. My hope with this was to see if there was a similarity that I could point out, but it is specific too what I have pointed out in the code. I don't get it at all, it makes no sense to me. I also tried returning simple values like just a string into the return and it ended up as None as well.

Comments You May Skip Over:

Why does this return None when it has a literal value???

Keep in mind that this function only does this when their are two itemsin the obj dictionary when their not in orderIt works when in order and when in the number of items is greater or lesser then 2WOuld put in return statement to save lines, but it returns NoneUnder the specific condition mentioned, the alteration ofVariables work just fine.


Viewing all articles
Browse latest Browse all 210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>