def sort_by_length(words):
if words!=None:
words= words.sort(key=len, reverse=True)
return words
def single_sort_by_len_test(input, result):
assert result == sort_by_length(list(input))
single_sort_by_len_test(["dog", "apple", "bear"], ["apple", "bear", "dog"])
这里的单词返回None
值。但答案应该是["apple", "bear", "dog"]
。无法看出问题所在。