我有这个:
list_one = [[['id'], ['value']], [['id'], ['value2']] , [['id'], ['value3']]]
我想拥有的是:
list_two = [['id'], ['value'], ['value2'], ['value3']]
基于list_one中的每个id。
非常感谢帮助。
答案 0 :(得分:1)
你可以试试这个:
import itertools
list_one = [[['id'], ['value']], [['id'], ['value2']] , [['id'], ['value3']]]
new_data = list(set(i[0] for i in itertools.chain.from_iterable(list_one)))
final_list = list(map(lambda x: [x], sorted(new_data, key=len))) #must be casted to a list in Python3 because map returns a map instance.