2006年01月23日 星期一 15:52
python,您好! 如下的字符串: """ ABC:123 DEF:456 ... """ 怎么方便的转换成字典?PYTHON下什么方法最简单呢? 谢谢 致 礼! cry zyqmail at tom.com
2006年01月23日 星期一 15:56
dict = {} for line in string: item = line.split(":") dict[item[0]]=item[1] 在 06-1-23,cry<zyqmail at tom.com> 写道: > python,您好! > > 如下的字符串: > """ > ABC:123 > DEF:456 > ... > """ > 怎么方便的转换成字典?PYTHON下什么方法最简单呢? > > 谢谢 > > 致 > 礼! > > 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 > -- """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/ """
2006年01月23日 星期一 16:12
dict(line.split(':') for line in astring.split('\n')) ----- 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下什么方法最简单呢? 谢谢 致 礼! 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
2006年01月23日 星期一 16:15
在 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/ """
2006年01月23日 星期一 16:39
string=""" abc:123 def:456 ghi:789 """ dict={} string=string[1:] string.splitlines() for item in string: item=item.split(':') dict.setdefault(item[0],item[1]) 2006/1/23, Zoom Quiet <zoom.quiet at gmail.com>: > > dict = {} > for line in string: > item = line.split(":") > dict[item[0]]=item[1] > > 在 06-1-23,cry<zyqmail at tom.com> 写道: > > python,您好! > > > > 如下的字符串: > > """ > > ABC:123 > > DEF:456 > > ... > > """ > > 怎么方便的转换成字典?PYTHON下什么方法最简单呢? > > > > 谢谢 > > > > 致 > > 礼! > > > > 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 > > > > > -- > """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 > > -- 祝你开心 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060123/742e5466/attachment.htm
2006年01月23日 星期一 16:41
在06-1-23,杨斌斌 <yangbb at gmail.com> 写道: > > string=""" > abc:123 > def:456 > ghi:789 > """ > dict={} > string=string[1:] > string=string.splitlines() > for item in string: > item=item.split(':') > dict.setdefault(item[0],item[1]) > > > > 2006/1/23, Zoom Quiet <zoom.quiet at gmail.com>: > > > > dict = {} > > for line in string: > > item = line.split(":") > > dict[item[0]]=item[1] > > > > 在 06-1-23,cry< zyqmail at tom.com> 写道: > > > python,您好! > > > > > > 如下的字符串: > > > """ > > > ABC:123 > > > DEF:456 > > > ... > > > """ > > > 怎么方便的转换成字典?PYTHON下什么方法最简单呢? > > > > > > 谢谢 > > > > > > 致 > > > 礼! > > > > > > 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 > > > > > > > > > -- > > """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 > > > > > > > -- > 祝你开心 -- 祝你开心 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060123/cedcf55e/attachment.html
Zeuux © 2025
京ICP备05028076号