我正在尝试将句子转换为列表格式而没有空格分隔符我尝试过以下方式
a = 'this is me'
当我使用split进入列表格式时
a.split(' ')
# ['this', 'is', 'me']
list(a)
# ['t','h','i','s','m','e']
有没有办法将输入作为
a = 'this is me'
并获得输出为
a = ['this is me']
使用此:-
>>> a = 'this is me'
>>> [a]
['this is me']
使用list
使函数在不需要的字符串上进行迭代。请改用那些大括号作为列表构造函数。
IN: a= 'this is me'
IN: a = [a]
IN: print(a)
OUT: ['this is me']
" ".join(a.strip().split(" "))