题目描述
Given a line of alphabetic characters , extract all the uppercase characters to print them on the first line . Then extract all the lowercase characters to print them on the second.
Example:
input | ouput |
---|---|
ABCDefghIJKLmnop | ABCDJKL efghmnop |
题目分析
题目大意:
题目要求我们把输入的字符串大小写分开输出。
解题代码
我写的:
t=input()
list1=list(t)
list2=[]
list3=[]
for s in list1:
if 'a'<=s<='z':
list2+=s
elif 'A'<=s<='Z':
list3+=s
s1,s2,s3,s4='','','',''
for s1 in list2:
s3+=s1
for s2 in list3:
s4+=s1
print(s3)
print(s4)
大佬写的:
a=input()
str=''
print(str.join(i for i in a if 'a' <=i<='z'))
print(str.join(i for i in a if 'A' <=i<='Z'))
总结
- python中将一行代码放在for循环那行
- Python 用一行代码实现for循环初始化数组
- Python join()方法:jion方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
- 我真是太逊了!