![](/img/trans.png)
[英]Pandas is not recognizing words, but only letters. How can I do so when I slice, it gives me the words not the letters?
[英]How to print the slice of the list of words that only includes letters. python? But what am i missing?
这是我到目前为止所拥有的:
strVar = 'Together We Thrive, Class of 2025!'
def stringToList(string):
listRes = list(string.split(" "))
return listRes
strVar = 'Together We Thrive, Class of 2025!'
strVarList = print(stringToList(strVar))
我知道我需要 append 并在那里进行排序。
这些是说明:
我的答案应该是这样的:
['C', 'T', 'T', 'W', 'a', 'e', 'e', 'e', 'e', 'f', 'g', 'h', 'h', 'i', 'l', 'o', 'o', 'r', 'r', 's', 's', 't', 'v']
请尝试:
sorted([x for x in 'Together We Thrive, Class of 2025!' if x.isalpha()])
或者,传递已定义变量的名称。
这输出:
['C',
'T',
'T',
'W',
'a',
'e',
'e',
'e',
'e',
'f',
'g',
'h',
'h',
'i',
'l',
'o',
'o',
'r',
'r',
's',
's',
't',
'v']
请试试这个:
strvar = "Together we Thrive, Class of 2025!"
Listt=[ ]
for letter in strvar:
if (letter.isalpha()):
Listt.append(letter)
Listt.sort()
print(Listt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.