我有一个任务,按如下所示对列表进行排序:
Input: "Sorting1234"
Output: "ginortS1324"
如果不使用join(),用于或,而则在代码中的任何位置。 经过多次尝试按要求的方式排序后,我成功了,但我无法将其打印为字符串
^{pr2}$下面是我使用sorted()进行排序的算法:
st=input()
def iseven(x):
if x.isdigit():
return int(x)+9 if int(x)%2==0 else int(x)
res=sorted(st, key=lambda x: (x.isdigit(), x.isupper(), iseven(x), ord(x) ))
print(res)
请帮我这个忙
不使用join,持续或暂时:
隐式使用循环,但回答了您的问题!在
只需在调用
print()
时使用*
运算符将参数从列表中解压出来,并使用""
作为separator:您可以使用reduce,它不在禁止列表中。在代码末尾附加以下行:
相关问题 更多 >
编程相关推荐