我有一个元组列表:
shouldComponentUpdate(nextProps, nextState) {
//You can perform more logic here such as
//return this.props.update === nextProps.update
return nextProps.update;
}
和另一个字符串列表:
l1 = [(2, "text1"), (5, "text3"), (7, "text2")]
我想按l2的顺序对l1进行排序,以使l1为:
l2 = ["text1", "text2", "text3"]
如何做到?
答案 0 :(得分:0)
l1.sort(key=lambda x: l2.index(x[1]))