题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
Using key = str.lower
is faster in speed...
while True:
try:
ipt = input()
# 1. sort out all characters
a = ''
for i in ipt:
# add to new string only if it is an English character
if i.isalpha():
a += i
b = sorted(a, key = str.lower)
# 2. add other non-characters
index = 0
c = ''
for i in range(0, len(ipt)):
if ipt[i].isalpha():
c += b[index]
index += 1
else:
c += ipt[i]
print(c)
except:
break