python 列表降维的实例讲解
作者:何宽 时间:2023-08-28 16:44:54
列表降维(python:3.x)
之前遇到需要使用列表降维的情况,
如:
原列表 : [[12,34],[57,86,1],[43,22,7],[1,[2,3]],6]
转化为 : [12, 34, 57, 86, 1, 43, 22, 7, 1, 2, 3, 6]
思路:
把列表转化为字符串,直接去掉 “[“ 和 “]”
最后由字符串转化为列表
a = [[12,34],[57,86,1],[43,22,7],[1,[2,3]],6]
#把列表转为字符串
b = str(a)
#替换掉'['和']'
b = b.replace('[','')
b = b.replace(']','')
#最后转化成列表
a = list(eval(b))
print(a)
执行结果 : [12, 34, 57, 86, 1, 43, 22, 7, 1, 2, 3, 6]
来源:https://blog.csdn.net/u013733326/article/details/78096511
标签:python,降维
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python创建简单的神经网络实例讲解
2021-12-02 05:38:41
![](https://img.aspxhome.com/file/2023/2/72762_0s.png)
Django与AJAX实现网页动态数据显示的示例代码
2022-11-05 01:10:17
python使用正则表达式来获取文件名的前缀方法
2023-02-08 07:37:58
Oracle数据库中表空间的基本管理操作小结
2024-01-26 23:18:26
![](https://img.aspxhome.com/file/2023/9/65239_0s.jpg)
通过底层源码理解YOLOv5的Backbone
2023-07-15 20:37:01
![](https://img.aspxhome.com/file/2023/5/103005_0s.jpg)
python实现字符串连接的三种方法及其效率、适用场景详解
2023-07-27 19:57:32
Django实战之用户认证(用户登录与注销)
2023-03-23 16:52:26
![](https://img.aspxhome.com/file/2023/9/88889_0s.png)
vue2.0开发实践总结之疑难篇
2024-05-02 16:33:28
![](https://img.aspxhome.com/file/2023/8/130238_0s.jpg)
javascript表单验证和Window详解
2023-07-14 02:14:38
python正则过滤字母、中文、数字及特殊字符方法详解
2022-02-20 10:14:47
一篇文章搞定数据库连接池
2024-01-19 02:55:49
JavaScript组件打包模式
2010-04-08 16:26:00
Python装饰器用法实例总结
2022-09-27 01:26:23
部署ASP.NET Core程序到Linux系统
2024-05-02 17:19:54
![](https://img.aspxhome.com/file/2023/8/129798_0s.jpg)
Python 图像处理: 生成二维高斯分布蒙版的实例
2023-01-31 16:29:06
![](https://img.aspxhome.com/file/2023/8/81538_0s.jpg)
Python Flask前后端Ajax交互的方法示例
2021-09-07 09:09:21
![](https://img.aspxhome.com/file/2023/0/75230_0s.png)
Python中的 any() 函数和 all() 函数
2023-05-05 08:38:50
Python实现PDF转换文本详解
2022-09-04 13:40:52
![](https://img.aspxhome.com/file/2023/2/107012_0s.jpg)
python使用SMTP发送qq或sina邮件
2021-03-08 01:06:55
![](https://img.aspxhome.com/file/2023/4/78454_0s.png)
省市县三级联动的SQL语句
2024-01-12 14:51:52