我有很多看起来像下面的字符串:
Einwohnerzahl
244.951
StudierendeamHochschulort
[...]
´´´
The words are separated now by "\n".
How can I seperated the whole words and numbers in separate lists? Because I got a lot of these strings which are not exactly the same I'am looking for a solution which can handele variations like different positions of the words / numbers or missing words / numbers in the string.
使用此:
s = 'apple\nbanana'
print(s.split('\n'))
输出:
['apple', 'banana']
如果您希望将其作为单独的词/短语:
s = 'apple\nbanana'
for i in s.split('\n'):
print(i)
输出:
apple
banana
https://www.geeksforgeeks.org/python-extract-words-from-given-string/该站点将帮助您解决问题。在发布堆栈溢出帖子之前,您应该尝试找到问题的答案。