Python论坛  - 讨论区

标题:[python-chinese] string to dict

2006年01月23日 星期一 16:28

cry zyqmail at tom.com
Mon Jan 23 16:28:27 HKT 2006

Zoom Quiet,您好!

受到启发,如下:
dict([line.split(":") for line in s.splitlines() if len(line) > 0])

谢谢Zoom Quiet和Slowness Chen。

Good luck

cry

在 2006-01-23 16:15:00 您写道:
>在 06-1-23,Slowness Chen<chenzh at bhh.com.cn> 写道:
>> dict(line.split(':') for line in astring.split('\n'))
>great!
>
>越来越 Pythonic 了
>
>> ----- Original Message -----
>> From: "cry" <zyqmail at tom.com>
>> To: "python" <python-chinese at lists.python.cn>
>> Sent: Monday, January 23, 2006 3:00 PM
>> Subject: [python-chinese] string to dict
>>
>>
>> python,您好!
>>
>> 如下的字符串:
>> """
>>     ABC:123
>>     DEF:456
>>     ...
>> """
>> 怎么方便的转换成字典?PYTHON下什么方法最简单呢?
>>
>> 谢谢
>>
>
>--
>"""Time is unimportant, only life important!
>my blog:  http://blog.zoomquiet.org/
>my wiki:   http://wiki.woodpecker.org.cn/moin/ZoomQuiet
>my book:  http://www.douban.com/group/zoomquiet/
>"""
>_______________________________________________
>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

                    致
礼!

            cry
            zyqmail at tom.com



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

2006年01月23日 星期一 16:29

Liming_Do Liming_Do at smics.com
Mon Jan 23 16:29:28 HKT 2006

"""
各位兄弟过年回家的也一路顺风啊!
回来之后就要启动一个大计划了,嘿嘿。plone相关的。
"""
嘿嘿,这么开心这么兴奋,原来明天就回家了
快过年了,大家一路顺风~~~~~
有众人可以参与的部分吆喝一声~~

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

2006年01月23日 星期一 16:39

Liming_Do Liming_Do at smics.com
Mon Jan 23 16:39:01 HKT 2006

cry兄,空格需要考虑么

-----Original Message-----
From: python-chinese-bounces at lists.python.cn
[mailto:python-chinese-bounces at lists.python.cn]On Behalf Of cry
Sent: Monday, January 23, 2006 4:28 PM
To: python-chinese at lists.python.cn
Subject: Re: Re: [python-chinese] string to dict


Zoom Quiet,您好!

受到启发,如下:
dict([line.split(":") for line in s.splitlines() if len(line) > 0])

谢谢Zoom Quiet和Slowness Chen。

Good luck

cry

在 2006-01-23 16:15:00 您写道:
>在 06-1-23,Slowness Chen<chenzh at bhh.com.cn> 写道:
>> dict(line.split(':') for line in astring.split('\n'))
>great!
>
>越来越 Pythonic 了
>
>> ----- Original Message -----
>> From: "cry" <zyqmail at tom.com>
>> To: "python" <python-chinese at lists.python.cn>
>> Sent: Monday, January 23, 2006 3:00 PM
>> Subject: [python-chinese] string to dict
>>
>>
>> python,您好!
>>
>> 如下的字符串:
>> """
>>     ABC:123
>>     DEF:456
>>     ...
>> """
>> 怎么方便的转换成字典?PYTHON下什么方法最简单呢?
>>
>> 谢谢
>>
>
>--
>"""Time is unimportant, only life important!
>my blog:  http://blog.zoomquiet.org/
>my wiki:   http://wiki.woodpecker.org.cn/moin/ZoomQuiet
>my book:  http://www.douban.com/group/zoomquiet/
>"""
>_______________________________________________
>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

                    致
礼!

            cry
            zyqmail at tom.com


_______________________________________________
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年01月23日 星期一 16:58

limodou limodou at gmail.com
Mon Jan 23 16:58:22 HKT 2006

在 06-1-23,Liming_Do<Liming_Do at smics.com> 写道:
> cry兄,空格需要考虑么
>
> Zoom Quiet,您好!
>
> 受到启发,如下:
> dict([line.split(":") for line in s.splitlines() if len(line) > 0])
>
> 谢谢Zoom Quiet和Slowness Chen。
>
> Good luck
>
> cry
>
> 在 2006-01-23 16:15:00 您写道:
> >在 06-1-23,Slowness Chen<chenzh at bhh.com.cn> 写道:
> >> dict(line.split(':') for line in astring.split('\n'))
> >great!
> >
> >越来越 Pythonic 了
> >
> >>
> >> python,您好!
> >>
> >> 如下的字符串:
> >> """
> >>     ABC:123
> >>     DEF:456
> >>     ...
> >> """
> >> 怎么方便的转换成字典?PYTHON下什么方法最简单呢?
> >>
> >> 谢谢
> >>
> >
a ="""
   ABC:123
   DEF:456
"""
import re
r = re.compile('(\w+):(\d+)', re.M)
b = dict(r.findall(a))
print b

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

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

2006年01月23日 星期一 17:02

Slowness Chen chenzh at bhh.com.cn
Mon Jan 23 17:02:33 HKT 2006

If you are using python 2.4, I'd like to recommend Generator Expressions.
It's more natural and memory-friendly.
----- Original Message ----- 
From: "cry" <zyqmail at tom.com>
To: <python-chinese at lists.python.cn>
Sent: Monday, January 23, 2006 4:28 PM
Subject: Re: Re: [python-chinese] string to dict


Zoom Quiet,您好!

受到启发,如下:
dict([line.split(":") for line in s.splitlines() if len(line) > 0])

谢谢Zoom Quiet和Slowness Chen。

Good luck

cry

在 2006-01-23 16:15:00 您写道:
>在 06-1-23,Slowness Chen<chenzh at bhh.com.cn> 写道:
>> dict(line.split(':') for line in astring.split('\n'))
>great!
>
>越来越 Pythonic 了
>
>> ----- Original Message -----
>> From: "cry" <zyqmail at tom.com>
>> To: "python" <python-chinese at lists.python.cn>
>> Sent: Monday, January 23, 2006 3:00 PM
>> Subject: [python-chinese] string to dict
>>
>>
>> python,您好!
>>
>> 如下的字符串:
>> """
>>     ABC:123
>>     DEF:456
>>     ...
>> """
>> 怎么方便的转换成字典?PYTHON下什么方法最简单呢?
>>
>> 谢谢
>>
>
>--
>"""Time is unimportant, only life important!
>my blog:  http://blog.zoomquiet.org/
>my wiki:   http://wiki.woodpecker.org.cn/moin/ZoomQuiet
>my book:  http://www.douban.com/group/zoomquiet/
>"""
>_______________________________________________
>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

                    致
礼!

            cry
            zyqmail at tom.com


_______________________________________________
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年01月23日 星期一 22:32

马踏飞燕 honeyday.mj at gmail.com
Mon Jan 23 22:32:54 HKT 2006

在 06-1-23,Liming_Do<Liming_Do at smics.com> 写道:
> """
> 各位兄弟过年回家的也一路顺风啊!
> 回来之后就要启动一个大计划了,嘿嘿。plone相关的。
> """
> 嘿嘿,这么开心这么兴奋,原来明天就回家了
> 快过年了,大家一路顺风~~~~~
> 有众人可以参与的部分吆喝一声~~
哈哈,好!!狗年大家都发一发旺一旺!

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

2006年01月24日 星期二 22:39

Fluke fluke.l at gmail.com
Tue Jan 24 22:39:27 HKT 2006

On 1/23/06, Slowness Chen <chenzh at bhh.com.cn> wrote:
>
> If you are using python 2.4, I'd like to recommend Generator Expressions.
> It's more natural and memory-friendly.


but what's Generator Expression?

----- Original Message -----
> From: "cry" <zyqmail at tom.com>
> To: <python-chinese at lists.python.cn>
> Sent: Monday, January 23, 2006 4:28 PM
> Subject: Re: Re: [python-chinese] string to dict
>
>
> Zoom Quiet,您好!
>
> 受到启发,如下:
> dict([line.split(":") for line in s.splitlines() if len(line) > 0])
>
> 谢谢Zoom Quiet和Slowness Chen。
>
> Good luck
>
> cry
>
> 在 2006-01-23 16:15:00 您写道:
> >在 06-1-23,Slowness Chen<chenzh at bhh.com.cn> 写道:
> >> dict(line.split(':') for line in astring.split('\n'))
> >great!
> >
> >越来越 Pythonic 了
> >
> >> ----- Original Message -----
> >> From: "cry" <zyqmail at tom.com>
> >> To: "python" <python-chinese at lists.python.cn>
> >> Sent: Monday, January 23, 2006 3:00 PM
> >> Subject: [python-chinese] string to dict
> >>
> >>
> >> python,您好!
> >>
> >> 如下的字符串:
> >> """
> >>     ABC:123
> >>     DEF:456
> >>     ...
> >> """
> >> 怎么方便的转换成字典?PYTHON下什么方法最简单呢?
> >>
> >> 谢谢
> >>
> >
> >--
> >"""Time is unimportant, only life important!
> >my blog:  http://blog.zoomquiet.org/
> >my wiki:   http://wiki.woodpecker.org.cn/moin/ZoomQuiet
> >my book:  http://www.douban.com/group/zoomquiet/
> >"""
> >_______________________________________________
> >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
>
>> 礼!
>
>            cry
>            zyqmail at tom.com
>
>
> _______________________________________________
> 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
>
>
> _______________________________________________
> 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
>
>


--
Yours,
  fluke
fluke at sfcube.net
http://sfcube.net/blog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060124/26e9d788/attachment.htm

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号