python里怎么把中文字符串转化为成list

  统计/机器学习 自然语言处理 Python    浏览次数:6390        分享
1

python里怎么把中文字符串转化为成list?

比如我有string = '机器学习',我怎么可以得到

list_string = ['机', '器', '学', '习']?

 

大王来巡山   2017-07-13 20:55



   2个回答 
4

我一般是先decode再encode

>>> string = '机器学习'
>>> list_string = map(lambda x: x.encode('utf-8'), string.decode('utf-8'))
>>> for i in list_string:
            print i
机
器
学
习
SofaSofa数据科学社区DS面试题库 DS面经

word哥   2017-07-15 23:18

这个是python2吧,现在python3很方便啊 - 木子周   2019-05-15 11:31
2

python3还是很方便的

a = '吃火锅'
print(list(a))

['吃', '火', '锅']

SofaSofa数据科学社区DS面试题库 DS面经

木子周   2019-05-15 11:32



  相关讨论

python字符串形式的数值转成单个整数的list,怎么操作?

python报错:'list' object has no attribute 'Angle',求教

返回python list里各个元素的大小排序?

re 不能在list 或者dataframe查找?

有nonetype的list怎么转str

python如何把list中的item作为变量的后缀 从而产生for中的动态变量名

怎么把字符串形式的list转成真的list

python怎么对list中的元素做连乘?

如何把一个pandas的dataframe的columns转换成list

怎么把pandas dataframe中的一列转成一个list?

  随便看看

概率论中的鞅是什么?

多个独立同分布的均匀随机变量的最小值的期望是多少?

numpy.array转换为图片并显示出来

print里的"%.2f"是什么意思?

逻辑回归的损失函数是怎么来的