文章详情页
python - 多维列表内一部分字符串型转换为整型
浏览:231日期:2022-06-30 15:53:58
问题描述
shell.txta1 b1 0.2 0a1 c1 0.8 0b1 c1 0.7 0a2 b2 1 0a2 d2 0.4 0d2 b2 0.6 0a1 a2 1 1a2 a1 0.1 1b1 b2 0.5 1b2 b1 0 1
with open(’shell.txt’) as f: lines = f.readlines()mylist = [line.strip().split() for line in lines]
由于txt数据加载后均为字符串型,现需要讲后两列转换为整型,求大佬给些clean的方法,谢谢
问题解答
回答1:result = []for i in f: s = i.split() result.append(s[:-2]+map(lambda x: int(float(x)), ss[-2:]))print result
相关文章:
1. linux - python 安装 Anaconda 环境变量问题请教2. css - transform-origin 旋转参考点3. css3动画 - css3 animation初始动画卡顿是怎么回事?4. PHP中的$this代表当前的类还是方法?5. 在别的电脑使用JDBC连接其他电脑上安装的mysql数据库6. html5 - api.douban.com/v2/movie/in_theaters?start=0&count=3 不在以下合法域名列表中7. php - 两个表数据怎么插到一个模板中,并按时间排序?8. python - pip install出现下面图中的报错 什么原因?9. mysql - 一个sql的问题10. 前端 - css自定义字体
排行榜

网公网安备