python将正负数分开存放

 

# -*- coding: utf-8 -*-
"""
Created on Fri Jul 24 09:37:44 2020

答疑: 李立宗  [email protected]
while语句
将正数,负数分组存放
"""
a=[-4,4,-56,66,77,-24,-55,-11,88,4,5,76,33,-100]
a1=[]
a2=[]
while len(a)>0:
    t=a.pop()
    if t>0:
        a1.append(t)
    else:
        a2.append(t)
print("正数集合:",a1)
print("负数集合:",a2)

 

你可能感兴趣的:(python,python,列表)