可以使用简洁的列表推导式
x = [1,5,-7]print sum([int(xi>0) for xi in x]) # 正数print sum([int(xi<0) for xi in x]) # 负数
来个简单的,for循环,弄个if,判断大于0和小于0,并做计数,
比如:
s = [1,5,-7]counter = 0for i in s: if i > 0: counter += 1print counter