Python论坛  - 讨论区

标题:[python-chinese] 求助:如何拆分一个字符串?

2007年06月22日 星期五 12:12

fei.He hefei267在gmail.com
星期五 六月 22 12:12:06 HKT 2007

ÎÒ¸Õ¿ªÊ¼½Ó´¥python£¬Åöµ½Á˸öСÎÊÌ⣬²»ÖªµÀÔõô½â¾ö£¬Çë´ó¼Ò°ï°ï棬ллÁË¡£

ÎÊÌâÊÇÕâÑùµÄ£º

Ò»¸ö×Ö·û´®£º
str1 = "abc123£¬#ÄãÎÒËû"

ÎÒÏ£Íû°ÑËü²ð·Ö³ÉÒ»¸ölist£º
ca1[0] = 'a'
ca1[1] = 'b'
ca1[2] = 'c'
ca1[3] = '1'
ca1[4] = '2'
ca1[5] = '3'
ca1[6] = '£¬'
ca1[7] = '#'
ca1[8] = 'Äã'
ca1[9] = 'ÎÒ'
ca1[10] = 'Ëû'
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070622/281bfe48/attachment.htm 

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

2007年06月22日 星期五 12:17

lai yonghao lanphaday在gmail.com
星期五 六月 22 12:17:39 HKT 2007

>>> l = list(unicode(str1, 'gbk'))
>>> l
[u'a', u'b', u'c', u'1', u'2', u'3', u'\uff0c', u'#', u'\u4f60', u'\u6211',
u'\u4ed6']
>>> for i in l:
 print i


a
b
c
1
2
3
£¬
#
Äã
ÎÒ
Ëû


ÔÚ07-6-22£¬fei. He <hefei267在gmail.com> дµÀ£º
>
> ÎÒ¸Õ¿ªÊ¼½Ó´¥python£¬Åöµ½Á˸öСÎÊÌ⣬²»ÖªµÀÔõô½â¾ö£¬Çë´ó¼Ò°ï°ï棬ллÁË¡£
>
> ÎÊÌâÊÇÕâÑùµÄ£º
>
> Ò»¸ö×Ö·û´®£º
> str1 = "abc123£¬#ÄãÎÒËû"
>
> ÎÒÏ£Íû°ÑËü²ð·Ö³ÉÒ»¸ölist£º
> ca1[0] = 'a'
> ca1[1] = 'b'
> ca1[2] = 'c'
> ca1[3] = '1'
> ca1[4] = '2'
> ca1[5] = '3'
> ca1[6] = '£¬'
> ca1[7] = '#'
> ca1[8] = 'Äã'
> ca1[9] = 'ÎÒ'
> ca1[10] = 'Ëû'
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070622/174c6697/attachment.html 

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

2007年06月22日 星期五 14:17

Liming_Do Liming_Do在smics.com
星期五 六月 22 14:17:09 HKT 2007

ÕâÖÖÇé¿ö²»ÐèÒª²ð·Ö°É£¬×Ö·û´®¾ÍÊÇsequence£¬ÓÃϱê»òÕßfor s in str1¶¼¿ÉÒÔѽ£¬Èç¹ûÓÐÖÐÎÄ»¹ÊÇȷʵÐèÒªunicodeһϵÄ
str1 = unicode("abc123£¬#ÄãÎÒËû",'gbk')
 
>>> for i in range(len(str1)):
 print str1[i]
 
 
a
b
c
1
2
3
£¬
#
Äã
ÎÒ
Ëû
>>> 
 
 
>>> for s in str1:
 print s
 
 
a
b
c
1
2
3
£¬
#
Äã
ÎÒ
Ëû

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn]On Behalf Of lai yonghao
Sent: Friday, June 22, 2007 12:18 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese]ÇóÖú£ºÈçºÎ²ð·ÖÒ»¸ö×Ö·û´®£¿



>>> l = list(unicode(str1, 'gbk'))
>>> l
[u'a', u'b', u'c', u'1', u'2', u'3', u'\uff0c', u'#', u'\u4f60', u'\u6211', u'\u4ed6'] 
>>> for i in l:
 print i


a
b
c
1
2
3
£¬
#
Äã
ÎÒ
Ëû



ÔÚ07-6-22£¬fei. He < hefei267在gmail.com> дµÀ£º 

ÎÒ¸Õ¿ªÊ¼½Ó´¥python£¬Åöµ½Á˸öСÎÊÌ⣬²»ÖªµÀÔõô½â¾ö£¬Çë´ó¼Ò°ï°ï棬ллÁË¡£

ÎÊÌâÊÇÕâÑùµÄ£º

Ò»¸ö×Ö·û´®£º
str1 = "abc123£¬#ÄãÎÒËû"

ÎÒÏ£Íû°ÑËü²ð·Ö³ÉÒ»¸ölist£º
ca1[0] = 'a'
ca1[1] = 'b'
ca1[2] = 'c'
ca1[3] = '1' 
ca1[4] = '2'
ca1[5] = '3'
ca1[6] = '£¬'
ca1[7] = '#'
ca1[8] = 'Äã' 
ca1[9] = 'ÎÒ'
ca1[10] = 'Ëû'

_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese



-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070622/39e738c2/attachment.htm 

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

2007年06月23日 星期六 08:53

fei.He hefei267在gmail.com
星期六 六月 23 08:53:24 HKT 2007

ÎÊÌâÒѾ­½â¾öÁË£¬Ð»Ð»Á½Î»

ÔÚ07-6-22£¬Liming_Do <Liming_Do在smics.com> дµÀ£º
>
>  ÕâÖÖÇé¿ö²»ÐèÒª²ð·Ö°É£¬×Ö·û´®¾ÍÊÇsequence£¬ÓÃϱê»òÕßfor s in str1¶¼¿ÉÒÔѽ£¬Èç¹ûÓÐÖÐÎÄ»¹ÊÇȷʵÐèÒªunicodeһϵÄ
> str1 = unicode("abc123£¬#ÄãÎÒËû",'gbk')
>
> >>> for i in range(len(str1)):
>  print str1[i]
>
>
> a
> b
> c
> 1
> 2
> 3
> £¬
> #
> Äã
> ÎÒ
> Ëû
> >>>
>
>
> >>> for s in str1:
>  print s
>
>
> a
> b
> c
> 1
> 2
> 3
> £¬
> #
> Äã
> ÎÒ
> Ëû
>
> -----Original Message-----
> *From:* python-chinese-bounces在lists.python.cn [mailto:
> python-chinese-bounces在lists.python.cn]*On Behalf Of *lai yonghao
> *Sent:* Friday, June 22, 2007 12:18 PM
> *To:* python-chinese在lists.python.cn
> *Subject:* Re: [python-chinese]ÇóÖú£ºÈçºÎ²ð·ÖÒ»¸ö×Ö·û´®£¿
>
> >>> l = list(unicode(str1, 'gbk'))
> >>> l
> [u'a', u'b', u'c', u'1', u'2', u'3', u'\uff0c', u'#', u'\u4f60',
> u'\u6211', u'\u4ed6']
> >>> for i in l:
>  print i
>
>
> a
> b
> c
> 1
> 2
> 3
> £¬
> #
> Äã
> ÎÒ
> Ëû
>
>
> ÔÚ07-6-22£¬fei. He <hefei267在gmail.com> дµÀ£º
> >
> > ÎÒ¸Õ¿ªÊ¼½Ó´¥python£¬Åöµ½Á˸öСÎÊÌ⣬²»ÖªµÀÔõô½â¾ö£¬Çë´ó¼Ò°ï°ï棬ллÁË¡£
> >
> > ÎÊÌâÊÇÕâÑùµÄ£º
> >
> > Ò»¸ö×Ö·û´®£º
> > str1 = "abc123£¬#ÄãÎÒËû"
> >
> > ÎÒÏ£Íû°ÑËü²ð·Ö³ÉÒ»¸ölist£º
> > ca1[0] = 'a'
> > ca1[1] = 'b'
> > ca1[2] = 'c'
> > ca1[3] = '1'
> > ca1[4] = '2'
> > ca1[5] = '3'
> > ca1[6] = '£¬'
> > ca1[7] = '#'
> > ca1[8] = 'Äã'
> > ca1[9] = 'ÎÒ'
> > ca1[10] = 'Ëû'
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070623/ab6b4ec2/attachment.html 

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

2007年06月23日 星期六 11:49

ricket在sjtu.edu.cn ricket在sjtu.edu.cn
星期六 六月 23 11:49:30 HKT 2007



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

2007年06月23日 星期六 14:32

XiaQ hn_sd_ywx_xiaq在163.com
星期六 六月 23 14:32:33 HKT 2007

str1 = "abc123,#你我他"
cal = list(str1)
fei.He 写道:
> 我刚开始接触python,碰到了个小问题,不知道怎么解决,请大家帮帮忙,谢谢了。
>
> 问题是这样的:
>
> 一个字符串:
> str1 = "abc123,#你我他"
>
> 我希望把它拆分成一个list:
> ca1[0] = 'a'
> ca1[1] = 'b'
> ca1[2] = 'c'
> ca1[3] = '1'
> ca1[4] = '2'
> ca1[5] = '3'
> ca1[6] = ','
> ca1[7] = '#'
> ca1[8] = '你'
> ca1[9] = '我'
> ca1[10] = '他'
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070623/90920067/attachment.html 

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

2007年06月23日 星期六 15:48

taohe taohe在mail.sdu.edu.cn
星期六 六月 23 15:48:53 HKT 2007

ÎÒÒ²ÊÇÐÂÊÖ£¬ÊÔÒ»ÏÂ

str1="abc123£¬#ÄãÎÒËû"
cal=[]
for str in str1:
     cal.append(str)
print cal





taohe
2007-06-23



·¢¼þÈË£º XiaQ
·¢ËÍʱ¼ä£º 2007-06-23 14:29:38
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]ÇóÖú£ºÈçºÎ²ð·ÖÒ»¸ö×Ö·û´®£¿

str1 = "abc123£¬#ÄãÎÒËû"
cal = list(str1)
fei.He дµÀ: 
ÎÒ¸Õ¿ªÊ¼½Ó´¥python£¬Åöµ½Á˸öСÎÊÌ⣬²»ÖªµÀÔõô½â¾ö£¬Çë´ó¼Ò°ï°ï棬ллÁË¡£

ÎÊÌâÊÇÕâÑùµÄ£º

Ò»¸ö×Ö·û´®£º
str1 = "abc123£¬#ÄãÎÒËû"

ÎÒÏ£Íû°ÑËü²ð·Ö³ÉÒ»¸ölist£º
ca1[0] = 'a'
ca1[1] = 'b'
ca1[2] = 'c'
ca1[3] = '1' 
ca1[4] = '2'
ca1[5] = '3'
ca1[6] = '£¬'
ca1[7] = '#'
ca1[8] = 'Äã'
ca1[9] = 'ÎÒ'
ca1[10] = 'Ëû'


_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070623/56f692e9/attachment.htm 

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号