list=['2','4','5','22','6','8','12'];
def function_name(list):
lens=len(list):
if(lens<2):
return list;
for i in range(lens):
string=array[i]
str=i
for j inrange(i,lens):
if list[j]
string=list[j]
str=j
ifi!=str:
list[i],list[str]=list[str],list[i]
return list;
#冒泡
def function_name2(list):
lens=len(list):
if(lens<=2):
returnarray;
for i in range(lens):
for j in range(lens-i-1):
if list[j+1]< list[j]:
list[j+1],list[j]=list[j],list[j+1]
return list;
#列表取模分割
def function_name3(arr):
result=[];
for idx, x in enumerate(arr):
print x;
a=idx%2+2;
result.setdefault(a,[]).append(x);
return result;
网友评论