标签:ascii码 提交 描述 for return 函数返回 sci 而不是 join
给一包含大写字母和整数(从 0
到 9
)的字符串, 试写一函数返回有序的字母以及数字和.
给出 str = AC2BEW3
, 返回 ABCEW5
字母按字母表的顺序排列, 接着是整数的和(2 和 3).
class Solution: """ @param str_ing: a string containing uppercase alphabets and integer digits @return: the alphabets in the order followed by the sum of digits """ def rearrange(self, str_ing): # Write your code here list_str = list(str_ing) number = [] letter = [] if str_ing == ‘‘: return ‘‘ for i in list_str: if i >= ‘0‘ and i <= ‘9‘: number.append(int(i)) elif i >= ‘A‘ and i <= ‘Z‘: letter.append(i) # sum_str = str(sum(number)) sum_str = str(sum(number)) letter.sort() letter.append(sum_str) str_letter = "".join(letter) return str_letter
标签:ascii码 提交 描述 for return 函数返回 sci 而不是 join
原文地址:https://www.cnblogs.com/yeshengCqupt/p/9905306.html