如何找到一种快速计算文本中每个单词之间的间距数的方法?
每个空格代表一个值,
示例:一个空格是字母“a”,两个空格是字母“b”等。
文本示例
文本:
hello all the world
hello 和 all 之间有一个空格 --> 'a',all 和 the 之间有两个空格 --> 'b', ...
单词 --> 'abc'
最佳答案
import re
import string
''.join(map(lambda x: string.lowercase[len(x) - 1], re.findall(r'\s+', 'hello all the world')))
# 'abc'
关于python - 每个单词之间的空格数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8864795/