Issue
def rev_sort(thelist):
'''
Reverses and then sorts the list entered
'''
thelist.sort()
thelist.reverse()
def main():
thelist = ["fun", "is", "programming"]
# rev_sort(thelist)
print(rev_sort(thelist))
main()
Calling main here outputs None, however, if I instead first use the function rev_sort and print the resulting list I get the decided output. However, I would expect it to be fine to do it like this, what's going on?
Solution
def rev_sort(thelist):
'''
Reverses and then sorts the list entered
'''
thelist.sort() # sort function return None
thelist.reverse() # reverse function returns None.
return thelist # you need to return the list back to main.
def main():
thelist = ["fun", "is", "programming"]
print(rev_sort(thelist))
main()
Answered By - Nesi Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.