我有以下元组列表:
items = [
('john jones', ['Director', 'Screenwriter', 'Producer']),
('eric smith', ['Screenwriter']),
('anne smith', ['Producer']),
('emily smith', ['Director']),
('steven jones', ['Director', 'Screenwriter'])
]
我需要对其进行排序,以使“导演”出现在“编剧”出现在“制片人”之前。其中的实际订购无关紧要。例如,这将是一个有效的结果:
items = [
('john jones', ['Director', 'Screenwriter', 'Producer']),
('emily smith', ['Director']),
('steven jones', ['Director', 'Screenwriter'])
('anne smith', ['Producer']),
('eric smith', ['Screenwriter']),
]
有没有办法做这种排序sorted(items, key=lambda x: ?)
,还是我必须迭代列表中的每个项目?