How to convert a string such as a = "I am Chinese"
into a list li =["I","是","中","国","人"]
a = "我是一个中国人"
li = list(a)
print li
The output is
['\xe6', '\x88', '\x91', '\xe6', '\x98', '\xaf', '\xe4', '\xb8', '\x80', '\xe4', '\xb8', '\xaa', '\xe4', '\xb8', '\xad', '\xe5', '\x9b', '\xbd', '\xe4', '\xba', '\xba']
I implemented it very simply using JavaScript
var a = "我是中国人"
li = a.split("")
console.log(li) // >>>["我","是","中","国","人"]
Don’t know how to implement it in python?
You can first decode the string into
unicode
, 再用list
Using python3
python3 has no encoding issues
1. No need to list(a), just
That’s it, it has nothing to do with coding, nor does it have to do with python2 or python3
2. You can directly treat a as a list. To obtain it, just use a[num] to slice it. For example, to obtain "I", it is a[0], and to obtain "China", you can use a[2:3]