python实现排序奇数在前偶数在后

方式一:
b=[1,2,3,4]
c=[x for x in b if x%2 == 0]
a=[x for x in b if x%2 != 0]
c.extend(a)
print(c)


方式二:
L = [1, 2, 3, 4, 5, 6]
index = 0
for _ in range(len(L)):
if L[index] % 2 == 1:
index += 1
else:
L.append(L.pop(index))
print(L)
posted @ 2018-05-22 21:03  孟庆健  阅读(3151)  评论(0编辑  收藏  举报