首页 > 解决方案 > 使用 Python 3.6.0 检索 Map() 值

问题描述

我查看了其他示例(例如Getting a map() to return a list in Python 3.x),但我无法弄清楚。我正在尝试打开这样的列表(大约有一千行,但我在这里简称它)

xyz = [' 0.35587716 -2.11974747 -3.69604539',
       ' 0.32428861 -2.15566737 -3.61313426',
       ' 0.35329223 -2.19372613 -3.75673156']

进入这样的数组或浮点数列表

b = [[0.35587716, -2.11974747, -3.69604539],
     [0.32428861, -2.15566737, -3.61313426],
     [0.35329223, -2.19372613, -3.75673156]]

我试过以下

b = np.array(map(lambda x: map(int, x.split()), xyz))
b = [[int(y) for y in x.split()] for x in xyz]

with open("file.log") as f:
    lis=[map(int,line.split()) for line in f]

所有这些都给了我类似的东西:

<map object at 0x117a89390>
<map object at 0x117a89390>
<map object at 0x117a89390>

等等等等

但我不知道如何访问地图对象中的值。我正在使用 Python 3.6.0。我不知道该怎么办:(

标签: pythonpython-3.xpython-3.6

解决方案


推荐阅读