Python论坛  - 讨论区

标题:[python-chinese] pyCookBook 1-3 字典的构造

2005年11月07日 星期一 20:40

zhang yunfeng zhangyunfeng at gmail.com
Mon Nov 7 20:40:20 HKT 2005

为什么这一段在py2.3中不能执行呢?有什么类似的办法可以这样生成字典哪?

> 你也可以放弃一些简洁性来获得更高的威力。例如:
>
>      1 def dodict(*args, **kwds):
>    2     d = {}
>    3     for k, v in args: d[k] = v
>    4     d.update(kwds)
>    5     return d
>    6 tada = dodict(*data.items(  ), yellow=2, green=4)
>
>  [译者:在python2.3中,tada = dodict(*data.items( ), yellow=2, green=4)
> 不能执行。有一个语法错误]
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051107/28cc2f57/attachment.html

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

2005年11月07日 星期一 21:21

老K koria at 163.com
Mon Nov 7 21:21:04 HKT 2005

python-chinese,您好!

	   请问有没谁研究过PYTHON这个脚本语言的解释器源代码????
谢谢.

 		With 
	Best Regard!
 				

        老K
        koria at 163.com
          2005-11-07

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

2005年11月07日 星期一 21:30

Jason Liu telecomliu at gmail.com
Mon Nov 7 21:30:55 HKT 2005

在 05-11-7,zhang yunfeng<zhangyunfeng at gmail.com> 写道:
>
>
> 为什么这一段在py2.3中不能执行呢?有什么类似的办法可以这样生成字典哪?
> >
> > 你也可以放弃一些简洁性来获得更高的威力。例如:
> >
> > 1 def dodict
(*args, **kwds):
> > 2 d = {}
> >
 3 for k, v in args
: d[k] = v
> >
 4 d.update(kwds)
> >
 5 return d
> > 6 tada
= dodict(*data.items(
), yellow=2, green
=4)
> >
> >
> >
> > [译者:在python2.3中,tada = dodict(*data.items( ), yellow=2, green=4)
> 不能执行。有一个语法错误]
>

*data.items( )是什么东西? " * "是什么?

> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
>
>

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

2005年11月07日 星期一 22:04

zhang yunfeng zhangyunfeng at gmail.com
Mon Nov 7 22:04:44 HKT 2005

在05-11-7,Jason Liu <telecomliu at gmail.com> 写道:
>
> 在 05-11-7,zhang yunfeng<zhangyunfeng at gmail.com> 写道:
> >
> >
> > 为什么这一段在py2.3中不能执行呢?有什么类似的办法可以这样生成字典哪?
> > >
> > > 你也可以放弃一些简洁性来获得更高的威力。例如:
> > >
> > > 1 def dodict
> (*args, **kwds):
> > > 2 d = {}
> > >
> 3 for k, v in args
> : d[k] = v
> > >
> 4 d.update(kwds)
> > >
> 5 return d
> > > 6 tada
> = dodict(*data.items(
> ), yellow=2, green
> =4)
> > >
> > >
> > >
> > > [译者:在python2.3中,tada = dodict(*data.items( ), yellow=2, green=4)
> > 不能执行。有一个语法错误]
> >
>
> *data.items( )是什么东西? " * "是什么?


data是之前定义的字典.
抱歉,忘记附上网址了 http://wiki.woodpecker.org.cn/moin/PyCkBk-1-3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20051107/2afe05c2/attachment.htm

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

2005年11月07日 星期一 22:25

Jason Liu telecomliu at gmail.com
Mon Nov 7 22:25:16 HKT 2005

在 05-11-7,zhang yunfeng<zhangyunfeng at gmail.com> 写道:
>
>
> 在05-11-7,Jason Liu <telecomliu at gmail.com> 写道:
> > 在 05-11-7,zhang yunfeng<zhangyunfeng at gmail.com> 写道:
> > >
> > >
> > > 为什么这一段在py2.3中不能执行呢?有什么类似的办法可以这样生成字典哪?
> > > >
> > > > 你也可以放弃一些简洁性来获得更高的威力。例如:
> > > >
> > > > 1 def dodict
> > (*args, **kwds):
> > > > 2 d = {}
> > > >
> > 3 for k, v in args
> > : d[k] = v
> > > >
> > 4 d.update(kwds)
> > > >
> > 5 return d
> > > > 6 tada
> > = dodict(*data.items (
> > ), yellow=2, green
> > =4)
> > > >
> > > >
> > > >
> > > > [译者:在python2.3中,tada = dodict(*data.items( ), yellow=2, green=4)
> > > 不能执行。有一个语法错误]
> > >
> >
> > *data.items( )是什么东西? " * "是什么?
>
> data是之前定义的字典.
> 抱歉,忘记附上网址了  http://wiki.woodpecker.org.cn/moin/PyCkBk-1-3

试了一下,好像只能用这种方式:

tada = dodict( *data.items( ), **{ 'yellow' : 2, 'green' : 4 } )

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

2005年11月08日 星期二 10:56

Fat fatbobman at gmail.com
Tue Nov 8 10:56:04 HKT 2005

>
> tada = dodict( *data.items( ), **{ 'yellow' : 2, 'green' : 4 } )
>

tada = dodict(yellow=2,green=4,*dota.items())

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号