gpt4 book ai didi

python - 从文件中读取数字并放入二维列表中

转载 作者:太空宇宙 更新时间:2023-11-04 10:52:04 26 4
gpt4 key购买 nike

我是 Python 新手。我的文件包含这些数字:

2,3
4,5
7,8
-4,3

如何读取此文件并将其转换为二维列表以便计算面积?

最佳答案

像这样:

>>> with open("data1.txt") as f:
... lis=[list(map(int,x.split(","))) for x in f]
... print lis
...
[[2, 3], [4, 5], [7, 8], [-4, 3]]

关于python - 从文件中读取数字并放入二维列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13210512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com