python映射对象在 [英] python map object at

查看:9
本文介绍了python映射对象在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python(3.41 版)的新手,我在打印使用 map 和 filter 函数的结果时遇到问题.我怎样才能找到这些结果?

<预><代码>>>>定义双(n):返回 n*2>>>li = [1,2,3]>>>地图(双,李)<0x000000000333DCF8处的映射对象>>>>打印(地图(双,li))<0x000000000333DC50处的映射对象>

解决方案

尝试以下任一方式:

print(list(map(double,li))

或者:

对于地图中的项目(double,li):打印(项目)

在 Python 3.4 中 map 将返回一个迭代器而不是一个列表(就像它在 2.7+ 中所做的那样).就内存占用而言,这很好,但它不能很好地映射到打印(双关语)

im new to Python (version 3.41) and I have a problem with printing the result of using map and filter function. How can I find these results?

>>> def double(n):
    return n*2

>>> li = [1,2,3]
>>> map(double, li)
<map object at 0x000000000333DCF8>
>>> print(map(double,li))
<map object at 0x000000000333DC50>

解决方案

Try either :

print(list(map(double,li))

Or :

for item in map(double,li):
    print(item)

In Python 3.4 map will return an iterator instead of a list (as it did in 2.7+). This is great as far as memory footprint is concerned but it doesn't map well to printing (pun intended)

这篇关于python映射对象在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆