["题名","作者","日期"]与{"作者":"A","题名":"B","日期":"F"}把列表里对应的key,替换成value,得到["B","A","F"],python如何实现
时间: 2024-02-09 08:05:48 浏览: 100
python中p-value的实现方式
在Python中,可以使用列表推导式来实现将列表中的对应键替换为值的操作。以下是实现的代码示例:
```python
data = ["题名", "作者", "日期"]
mapping = {"作者": "A", "题名": "B", "日期": "F"}
result = [mapping[key] for key in data]
print(result)
```
输出结果为:["B", "A", "F"]
阅读全文