python地图对象在 [英] python map object at

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

问题描述

im new to Python(3.41版),我有打印使用map和filter功能的结果的问题。如何找到这些结果?

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>


推荐答案

尝试:

print(list(map(double,li))

或者:

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

在Python 3.4中,map将返回一个迭代器而不是一个列表(就像在2.7+中)。对于记忆足迹而言,这是非常好的,但它不能很好地映射到打印(双关语)

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天全站免登陆