撰寫程式讀取一個字串內容 p,試著提取字串裡的英文字母,並按照 a-z 和 A-Z 順序輸出。
範例 1 輸入 |
範例 1 輸出 |
Hello, Taiwan. |
aaeillnowHT |
範例 2 輸入 |
範例 2 輸出 |
"This site is AWESOME." |
ehiiissstAEEMOSTW |
範例 3 輸入 |
範例 3 輸出 |
Linear and low-dropout (LDO) regulators are a simple, |
aaaaaddeeeegiilllmnnoooopprrrrrssttuuwDLLO |
範例 4 輸入 |
範例 4 輸出 |
Hello $hjelJohn_qyRETT5% |
eehhjlllnooqyEHJRTT |
ws=("Hello, Taiwan.","This site is AWESOME.","Linear and low-dropout (LDO) regulators are a simple,","Hello $hjelJohn_qyRETT5%")
def revstr(instr):
wss=[x for x in instr]
temp1=[]
temp2=[]
for loops in range(len(wss)):
if (wss[loops] >="A" and wss[loops] <="Z"):
temp1.append(wss[loops])
elif (wss[loops] >="a" and wss[loops] <="z"):
temp2.append(wss[loops])
temp1.sort()
temp2.sort()
temp =''.join(temp2)+''.join(temp1)
return(temp)
for i in range(len(ws)):
print(revstr(ws[i]))