易截截图软件、单文件、免安装、纯绿色、仅160KB

求助python,map filter

map,filter方法应该会返回一个列表。
但是在我这里,它们总是返回:
<map object at 0x0000000002A2C978>
<filter object at 0x0000000002A2C9E8>

我用的python3.1, 这个也是版本的变动导致的吗?

def map_func(lis):
  return lis + 1
li = [1,2,3,4,5]
map_l = map(map_func, li) #将li中所有的数都+1
print (map_l)

就是这个小程序,怎么加print?

看看这个
What's New In Python 3.0 http://blog.csdn.net/t_huanghai/archive/2008/12/04/3443782.aspx
里面有对python3.0 map()函数介绍,参考下 ,试试 print list(map_l)

map() and filter() return iterators. If you really need a list, a quick fix is e.g. list(map(...)), but a better fix is often to use a list comprehension (especially when the original code uses lambda), or rewriting the code so it doesn’t need a list at all. Particularly tricky is map() invoked for the side effects of the function; the correct transformation is to use a regular for loop (since creating a list would just be wasteful). 


What's New In Python 3.0

invalid syntax
看来,应该照它说的, 用for loop


谢谢小康

print (list(map_l))

correct format. mark it.


相关问答:

python 图像多边形切割

python的PIL库自带的方法只能进行矩形的切割,如果我有了一个多边形各个顶点的坐标,如何对现有的图片按照这个多边形进行切割呢?
不一定要用PIL库,任何能实现这个功能的方法都行。

图片切割的js不是很多吗?
......

python中字符串比较的问题的问题

以下代码是Tk做了一个简单的密码验证功能,输入一个字符串,并验证其是否正确,请先看代码:
Python code:

from tkinter import *
root = Tk()
e = StringVar()
t = 'cashlu'
def yanzheng():
if e ......

python解析xml文件

使用xml.dom解析几兆的xml文件,非常缓慢,有种假死的感觉。怎么解决?用其他库是否会好些,暂时只知道这个库的。
你可以试一下ElementTree


python的官方例子
import xml.parsers.expat

# 3 handler ......

python win下调用dll

  小弟接触python 2个星期了,安装的是python3.1版。
我用的是windows7,想写个调用dll的程序实践。问题来了:

C++代码:
extern "C" int __stdcall test();

int __stdcall te ......

如何将一段Python代码生成库

如何将Python写的一段代码生成pyd形式的库?
我知道的方法有:将这段Python代码扩展成C代码,然后通过VC将这段C代码生成后缀为.pyd的动态链接库。
不想用这么笨的方法,请问有没有比较简单的方法?谢谢!
顶一下, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号