def rearrange(number): str1=str(number) list1=[] for i in str1: if i!='0': list1.append(i) list2=sorted(list1) str2=''.join(str(i) for i in list2) number=int(str2) return number number=rearrange(10029001) print(number) #改良版 def rearrange(number): list1=[i for i in str(number) if i!='0'] #list1=list(str1.replace('0','')) str2=''.join(sorted(list1)) return (int(str2)) number=rearrange(10029001) print(number)
题目:
Returns an integer consisting of all nonzero digits in "number", from smallest to largest.
You can assume that "number" is a valid strictly positive integer.
>>> rearrange(1)
1
>>> rearrange(200)
2
>>> rearrange(395)
359
>>> rearrange(10029001)
1129
>>> rearrange(301302004)
12334
>>> rearrange(9409898038908908934890)
33448888889999999
’’’