输入50个正整数,将其中的偶数按升序排列,奇数按降序排列。若偶数个数多于奇数个数,则偶数放在数组的前边,奇数放在其后;否则奇数放在前,偶数在后;输出排序后的结果。
import random
xx=[random.randint(1,100) for _ in range(50)]
oushu=sorted(list(filter(lambda x:x if x%2==0 else None,xx)))
jishu=sorted(list(filter(lambda x:x if x%2==1 else None,xx)),reverse=True)
zonghe=jishu+oushu if len(oushu)>len(jishu):
zonghe=oushu+jishu
print(zonghe)