在python中删除字符串上的任何单个字母 [英] Removing any single letter on a string in python

查看:44
本文介绍了在python中删除字符串上的任何单个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 python 中的字符串中删除任何单个字母.

I would like to remove any single letter from a string in python.

例如:

input: 'z 23rwqw a 34qf34 h 343fsdfd'
output: '23rwqw 34qf34 343fsdfd'

一直试图用正则表达式找出一段时间,但没有成功.我知道如何将某些字符/符号中的东西分成两部分,但不知道我想要做什么.

Been trying to figure out for a while with regex without success. I know how to cut things from certain char/symbol in two pieces, but not what I am trying to do.

我一直在修补

re.sub(r'^[^ ]*', '', text)

推荐答案

>>> ' '.join( [w for w in input.split() if len(w)>1] )
'23rwqw 34qf34 343fsdfd'

这篇关于在python中删除字符串上的任何单个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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