当前位置:网站首页>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
边栏推荐
- 【TcaplusDB知识库】TcaplusDB运维单据介绍
- Adobe Premiere foundation - opacity (mixed mode) (XII)
- [how the network is connected] Chapter 3 explores hubs, switches and routers
- Redis(一)--Redis入门(2)--Redis数据类型
- 山东大学项目实训(六)点击事件展示折线图
- 细说GaussDB(DWS)复杂多样的资源负载管理手段
- centos 7.5安装mysql 8.0.27----yum
- 美法官裁定,被控掩盖黑客行为的Uber前安全主管必须面对欺诈指控
- Shell basic syntax -- process control
- Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket
猜你喜欢

报错Failed to allocate graph: MYRIAD device is not opened.

centos 7.5安装mysql 8.0.27----yum

Adobe Premiere foundation - cool text flash (14)

2. add customized related files to the keil5 project established by stm32cubemx

How to use the oak camera on raspberry pie?

markdown知识轻轻来袭

How to use the low code platform of the Internet of things for service management?

The strategy of convertible bonds -- - (cake sharing, premium, forced redemption, downward revision, double low)

Adobe Premiere基础-不透明度(蒙版)(十一)

Travel card "star picking" hot search first! Stimulate the search volume of tourism products to rise
随机推荐
Sd6.23 summary of intensive training
程序员资源推荐指南
idea怎么使用?
保持jupyter notebook在终端关闭时的连接方法
第02章_MySQL的数据目录
My first experience of remote office | community essay solicitation
MySQL -connector/j driver download
[Nanjing University] information sharing of the first and second postgraduate entrance examinations
Machine learning 7-Support vector machine
2. add customized related files to the keil5 project established by stm32cubemx
Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
1. 使用STM32CubeMX建立STM32G030C8T6项目工程
Mac: MySQL 66 questions, 20000 words + 50 pictures!
Interview question 10.10 Rank of digital stream
C Primer Plus Chapter 12_ Storage categories, links, and memory management_ Codes and exercises
Chapter 02_ MySQL data directory
剑指 Offer 34. 二叉树中和为某一值的路径-dfs法
curl下载示例
How to use the oak camera on raspberry pie?
Notes on spintronics - zhangshufeng