[Tutor] (no subject)
Kent Johnson
kent37 at tds.net
Thu Aug 25 18:57:40 CEST 2005
Jorge Louis de Castro wrote:
> Hi,
>
> What is the best way to split a unicode string in its characters?
> Specifically, having this unicode chinese string
>
> u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48
>
> I want to either split all its characters:
> [\u8C01,\u4ECA,\u5929,\u7A7F,\u4EC0,\u4E48]
>>> s=u'\u8C01\u4ECA\u5929\u7A7F\u4EC0\u4E48'
>>> list(s)
[u'\u8c01', u'\u4eca', u'\u5929', u'\u7a7f', u'\u4ec0', u'\u4e48']
> or insert a space between each character:
> \u8C01 \u4ECA \u5929 \u7A7F \u4EC0 \u4E48
>>> ' '.join(list(s))
u'\u8c01 \u4eca \u5929 \u7a7f \u4ec0 \u4e48'
Kent
More information about the Tutor
mailing list