当前位置:网站首页>isalpha()方法介绍
isalpha()方法介绍
2022-06-29 18:29:00 【是乔乔啊】
介绍
str.isalpha()实现的是如果字符串至少有一个字符并且所有字符都是字母则返回 True,否则返回 False。
应用:
例如ACM算法中有一道排序题:
编写一个程序,将输入字符串中的字符按如下规则排序。
规则 1 :英文字母从 A 到 Z 排列,不区分大小写。
如,输入: Type 输出: epTy
规则 2 :同一个英文字母的大小写同时存在时,按照输入顺序排列。
如,输入: BabA 输出: aABb
规则 3 :非英文字母的其它字符保持原来的位置。
如,输入: By?e 输出: Be?y
数据范围:输入的字符串长度满足 1 \le n \le 1000 \1≤n≤1000
输入描述:
输入字符串
输出描述:
输出字符串
输入:A Famous Saying: Much Ado About Nothing (2012/8).
输出:A aaAAbc dFgghh: iimM nNn oooos Sttuuuy (2012/8)
代码:
while True:
try:
s = input()
a = ''
for i in s:
if i.isalpha(): # 进行字母类型判断
a += i
b = sorted(a, key=str.upper) # 根据大写ASC码排序
index = 0
d = ''
for i in range(len(s)):
if s[i].isalpha():
d += b[index]
index += 1
else:
d += s[i]
print(d)
except:
break
边栏推荐
- Basis of data analysis -- prediction model
- Usage of BeanUtils property replication
- postgis 生成 图形切割
- curl下载示例
- Source code installation mavros
- 山东大学项目实训(八)设计轮播图进入页面
- 行程卡“摘星”热搜第一!刺激旅游产品搜索量齐上涨
- Svg circle drawing path animation
- These advantages of the Institute are really fragrant! The landing rate is still very high!
- Us judge ruled that the former security director of Uber accused of covering up hacking must face fraud charges
猜你喜欢

Travel card "star picking" hot search first! Stimulate the search volume of tourism products to rise

Machine learning 8-artificial neural network

龙canvas动画

Adobe Premiere foundation - cool text flash (14)

【网络是怎么连接的】第三章 探索集线器,交换机和路由器

These advantages of the Institute are really fragrant! The landing rate is still very high!

Adobe Premiere foundation - opacity (matte) (11)
![Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket

Error building sqlsession problem

1. use stm32cubemx to establish stm32g030c8t6 project
随机推荐
JWT login authentication
Sister Juan takes you to learn database -- 5-day sprint Day1
Machine learning 7-Support vector machine
Fastdfs
Request header field XXXX is not allowed by access control allow headers in preflight response
细说GaussDB(DWS)复杂多样的资源负载管理手段
How to use the low code platform of the Internet of things for service management?
如何将OAK相机当做网络摄像头使用?
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
关于微服务
2. 在STM32CubeMX建立的Keil5工程中添加自定义的相关文件
About microservices
MySQL Enterprise Development Specification
SD6.24集训总结
Adobe Premiere基础-不透明度(蒙版)(十一)
Adobe Premiere foundation - material nesting (animation of Tiktok ending avatar) (IX)
【TcaplusDB知识库】TcaplusDB运维单据介绍
Encryption and decryption of 535 tinyurl
【网络是怎么连接的】第三章 探索集线器,交换机和路由器
Adobe Premiere foundation - opacity (mixed mode) (XII)