朋友们,告诉我,你需要在给定数字的数字总和的情况下对一行或一张表中的数字进行排序。例如字符串 103, 90 将被排序为 103, 90 所以 1+3+0 = 4, 9+0 = 9
为排序函数组合键时出现问题。
def valid_parentheses(string):
return sorted(string, key=[sum(map(int, str(x))) for x in string.split(' ')])
print(valid_parentheses('103 90'))
如果输入数据是列表中的数字:
如果原始数据是一行中的数字,则通过空格写入: