python 将字典转为数组
时间: 2023-12-20 14:06:31 浏览: 108
python将字符串转换成数组的方法
以下是将多个字典转换为字典数组的Python代码示例:
```python
dict1 = {'a0': 1, 'b0': 2}
dict2 = {'a1': 11, 'b1': 22}
dict3 = {'a2': 111, 'b2': 222}
dict_array = [dict1, dict2, dict3]
print(dict_array)
```
输出结果为:
```
[{'a0': 1, 'b0': 2}, {'a1': 11, 'b1': 22}, {'a2': 111, 'b2': 222}]
```
以下是将字典转换为数组的Python代码示例:
```python
my_dict = {"x": 1, "y": 2, "z": 3}
my_list = list(my_dict.items())
print(my_list)
```
输出结果为:
```
[('x', 1), ('y', 2), ('z', 3)]
```
阅读全文