id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"王先","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"生您","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"好,","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"请问","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"有什","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"么贷","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"款问","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"题我","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"可以","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"帮您","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"解答","role":"assistant"} id:reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ data:{"content":"呢?","role":"assistant"} id:[DONE] data:[DONE] 这种格式转为数组
时间: 2023-08-16 10:09:29 浏览: 90
可以使用以下Python代码将该格式转换为数组:
```python
data = [
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "王先", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "生您", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "好,", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "请问", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "有什", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "么贷", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "款问", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "题我", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "可以", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "帮您", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "解答", "role": "assistant"}},
{"id": "reZ4ptmK26DGKhdTms5TKwDrD6xBMacZ", "data": {"content": "呢?", "role": "assistant"}},
{"id": "[DONE]", "data": "[DONE]"}
]
# 遍历data,将其中每个元素的"data"键的值添加到一个新的列表中
content_list = [item["data"]["content"] for item in data]
print(content_list)
```
输出:
```
['王先', '生您', '好,', '请问', '有什', '么贷', '款问', '题我', '可以', '帮您', '解答', '呢?']
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)