Python 修复函数的去bug
我正在调试以下函数:Python 修复函数的去bug,python,Python,我正在调试以下函数: def buggy_dedup_sort_by_len(input): unique = list(set(input)) return unique.sort(key=len) 列表已排序,但unique.sort(key=len)未返回任何内容。 函数list.sort不会返回任何内容。我如何修复它?返回None,因为它会在适当的位置修改列表。尝试: def buggy_dedup_sort_by_len(input): unique = list(set(i
def buggy_dedup_sort_by_len(input):
unique = list(set(input))
return unique.sort(key=len)
列表已排序,但unique.sort(key=len)未返回任何内容。
函数list.sort不会返回任何内容。我如何修复它?返回None
,因为它会在适当的位置修改列表。尝试:
def buggy_dedup_sort_by_len(input):
unique = list(set(input))
unique.sort(key=len)
return unique
或者,使用,它将返回一个列表
def buggy_dedup_sort_by_len(input):
unique = list(set(input))
return sorted(unique, key=len)
相关的: