编写一个python函数create_largest_number(),该函数接受数字列表,并通过连接数字列表来返回最大的数字。 样本输入= 23,34,55 预期输出= 553423
def create_largest_number(number_list):
number=[]
for i in number_list:
while i>0:
number.append(i%10)
i=i//10
number.sort(reverse=True)
z= ''.join(str(num) for num in number)
return int(z)
number_list = [23, 45, 67]
largest_number = create_largest_number(number_list)
print(largest_number)[result after submission][1]
答案 0 :(得分:1)
不确定您的解决方案,但您可以尝试以下方法:
def create_largest_number(number_list):
number_list.sort(reverse=True)
z= ''.join(str(num) for num in number)
return int(z)