Python论坛  - 讨论区

标题:[python-chinese] 关于map和tuple

2006年07月05日 星期三 18:37

linda.s samrobertsmith at gmail.com
Wed Jul 5 18:37:15 HKT 2006

以下程序为什么错?
>>> q
['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
>>> q[0].split()
['11', '1', '5', '5']
>>> w=map(int,q[0].split())
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: 'tuple' object is not callable
我查了map
>>> map

但是奇怪的是我没有命名过任何map的东西.
如果我还是想用map
的功能,怎么办?

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月05日 星期三 18:58

Leo Jay python.leojay at gmail.com
Wed Jul 5 18:58:40 HKT 2006

On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote:
> 以下程序为什么错?
> >>> q
> ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
> >>> q[0].split()
> ['11', '1', '5', '5']
> >>> w=map(int,q[0].split())
> Traceback (most recent call last):
>  File "", line 1, in ?
> TypeError: 'tuple' object is not callable


奇怪,在我这里是对的嘛:
>>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
>>> w = map(int, q[0].split())
>>> w
[11, 1, 5, 5]
>>>

-- 
Best Regards,
Leo Jay

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月05日 星期三 19:04

刘鑫 march.liu at gmail.com
Wed Jul 5 19:04:16 HKT 2006

你自己给出的操作已经解释了这个问题,仔细看看那个信息你就明白,map是Python的内置函数,用于对线形容器执行函数化操作,具体来说,是把对某个(或多个)序列中所有元素的操作结果映射到另一个序列中。

>>> help(map)
Help on built-in function map in module __builtin__:

map(...)
    map(function, sequence[, sequence, ...]) -> list

    Return a list of the results of applying the function to the items of
    the argument sequence(s).  If more than one sequence is given, the
    function is called with an argument list consisting of the corresponding
    item of each sequence, substituting None for missing values when not all
    sequences have the same length.  If the function is None, return a list
of
    the items of the sequence (or a list of tuples if more than one
sequence).

help用起来很方便,要善于利用,map的用法在tut里有,Python自带的官方教程。并不长,建议初学者都读一读。


-- 
欢迎访问:
http://blog.csdn.net/ccat

刘鑫
March.Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060705/78bf51ab/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月05日 星期三 19:05

Dreamingk(天成) dreamingk at gmail.com
Wed Jul 5 19:05:30 HKT 2006

你的 int   和   map 是不是被你赋值了?

On 7/5/06, Leo Jay <python.leojay at gmail.com> wrote:
> On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote:
> > 以下程序为什么错?
> > >>> q
> > ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
> > >>> q[0].split()
> > ['11', '1', '5', '5']
> > >>> w=map(int,q[0].split())
> > Traceback (most recent call last):
> >  File "", line 1, in ?
> > TypeError: 'tuple' object is not callable
>
>
> 奇怪,在我这里是对的嘛:
> >>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
> >>> w = map(int, q[0].split())
> >>> w
> [11, 1, 5, 5]
> >>>
>
> --
> Best Regards,
> Leo Jay
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年07月05日 星期三 19:08

Dreamingk(天成) dreamingk at gmail.com
Wed Jul 5 19:08:24 HKT 2006

不用 map也行阿 ,  [int(c) for c in q[0].split()]
比用map清晰

On 7/5/06, Dreamingk(天成) <dreamingk at gmail.com> wrote:
> 你的 int   和   map 是不是被你赋值了?
>
> On 7/5/06, Leo Jay <python.leojay at gmail.com> wrote:
> > On 7/5/06, linda. s <samrobertsmith at gmail.com> wrote:
> > > 以下程序为什么错?
> > > >>> q
> > > ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
> > > >>> q[0].split()
> > > ['11', '1', '5', '5']
> > > >>> w=map(int,q[0].split())
> > > Traceback (most recent call last):
> > >  File "", line 1, in ?
> > > TypeError: 'tuple' object is not callable
> >
> >
> > 奇怪,在我这里是对的嘛:
> > >>> q = ['11 1 5 5', '22 5 5 1', '103 1 15 10', '114 10 15 1', '12 2 20 2']
> > >>> w = map(int, q[0].split())
> > >>> w
> > [11, 1, 5, 5]
> > >>>
> >
> > --
> > Best Regards,
> > Leo Jay
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号