您能否在Python中将此函数缩短为3行? [关闭]

问题描述 投票:-2回答:1
def concat_sort(nested_list):
    new_list=[]
    for sub_list in nested_list:
        for element in sub_list:
            new_list.append(element)
    return sorted(list(set(new_list)))

此函数从嵌套列表中返回排序后的元素。

python
1个回答
0
投票
def concat_sort(nested_list): return sorted(set(sum(nested_list, [])))
© www.soinside.com 2019 - 2024. All rights reserved.