编写函数,模拟内置函数 sorted()。
用python来简单的模拟sorted可以用库函数来进行,也较为简单,我选了min()和sort()来进行模拟
利用min()函数
def sorteds(items):
temp = items[:]
result = []
while temp:
u = min(temp)
result.append(u)
temp.remove(u)
return result #利用min函数来判断大小
利用sort()函数
def sorteds(items):
temp = items[:]
temp.sort()
return temp
#直接用sort来进行sorted的操作