# return str of the smallest value of the combined numbers in a_list
# the length of a_list can vary betweem 2 and 20
def penalty(a_list):return ''.join(sorted(a_list, cmp=(lambda a, b: cmp(a+b, b+a))))
def penalty(lst):lst, maxLen = list(map(str, lst)), max(map(len, lst))return ''.join(sorted(lst, key=lambda s: s.ljust(maxLen, s[-1])))
# return str of the smallest value of the combined numbers in a_list
def penalty(a_list):return ''.join(sorted(a_list, key = lambda n: n + n[:1]))
penalty=lambda a:''.join(sorted(a,key=lambda n:2*n))
from functools import cmp_to_keydef penalty(a_list):return ''.join(sorted(a_list, key = cmp_to_key(sorter)))def sorter(a, b):return -1 if a + b < b + a else 1
# return str of the smallest value of the combined numbers in a_list
# the length of a_list can vary betweem 2 and 20
def penalty(l):return "".join(sorted(l, key=lambda k: (k*2, -len(k))))
# return str of the smallest value of the combined numbers in a_list
# the length of a_list can vary betweem 2 and 20
def penalty(i):a = sorted(i, key=lambda k:(k*1000, -len(k)))return "".join(a)
# return str of the smallest value of the combined numbers in a_list
# the length of a_list can vary betweem 2 and 20 def penalty(a_list):return ''.join(sorted(a_list, cmp=lambda x,y: int(x+y) - int(y+x) ))
def penalty(a):m = len(max(a, key=len))return "".join(x[:len(x)//m] for x in sorted(x * m for x in a))
from functools import cmp_to_keydef cmp (a, b):
# should be a > b if a[0] > b[0]
# if a[0] == b[0], should be a > b if a[1] a = list(a)b = list(b)if a == b:return 0if int(a[0]) < int(b[0]):return -1elif int(a[0]) > int(b[0]):return 1else: #a[0] == b[0]if len(a) > 1 and len(b) > 1:return cmp(a[1:], b[1:])elif len(a) > 1 and len(b) == 1:return (-1 if int(a[1]) < int(b[0]) else 1)elif len(a) == 1 and len(b) > 1:return (-1 if int(a[0]) < int(b[1]) else 1)def penalty(a_list):print(a_list) return ''.join(sorted(a_list,key = cmp_to_key(cmp)))
景越Python基础训练营QQ群
欢迎各位同学加群讨论,一起学习,共同成长!
本文发布于:2024-02-03 04:30:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170690579948657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |