每个单词之间的空格数 [英] number of space between each word

查看:43
本文介绍了每个单词之间的空格数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何快速计算文本中每个单词之间的间距数?

How can I find a quick way to count the number of spacing between each word in a text?

每个空格代表一个值,

例如:一个空格是字母'a',两个空格是字母'b',等等.

Example: one space is the letter 'a', two spaces is the letter 'b', etc..

文本示例

文本:

hello all  the   world 

hello 和 all 之间有一个空格 --> 'a',all 和 the 之间有两个空格 --> 'b', ...

one space between hello and all --> 'a', two spaces between all and the --> 'b', ...

word --> 'abc'

推荐答案

import re
import string

''.join(map(lambda x: string.lowercase[len(x) - 1], re.findall(r'\s+', 'hello all  the   world')))
# 'abc'

这篇关于每个单词之间的空格数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆