字符串排序
字符串排序
http://www.nowcoder.com/questionTerminal/5190a1db6f4f4ddb92fd9c365c944584
def sortStr(inStr): res = [0] * len(inStr) helpLs = [] for i, s in enumerate(inStr): if s.isalpha(): helpLs.append(s) else: res[i] = s helpLs.sort(key = lambda x : x.upper()) for i, v in enumerate(res): if not v: # 这个地方要注意0和'0', res中的0代表空值,'0'代表原字符串中的'0'被安排在该位置。 res[i] = helpLs[0] helpLs.pop(0) return ''.join(res) if __name__ == "__main__": while True: try: inStr = input().strip() res = sortStr(inStr) print(res) except: break