Why does “return list.sort()” return None, not the list?

前端 未结 7 739
感情败类
感情败类 2020-11-21 06:55

I\'ve been able to verify that the findUniqueWords does result in a sorted list. However, it does not return the list. Why?

def fin         


        
7条回答
  •  旧时难觅i
    2020-11-21 07:28

    The problem is here:

    answer = newList.sort()
    

    sort does not return the sorted list; rather, it sorts the list in place.

    Use:

    answer = sorted(newList)
    

提交回复
热议问题