2006年01月23日 星期一 16:57
Liming_Do,您好! 再加上个strip就可以了。 在 2006-01-23 16:39:00 您写道: >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 >_______________________________________________ >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
Zeuux © 2025
京ICP备05028076号