0
help please
Write a function called manipulate_data which will act as follows: When given a list of integers, return a list, where the first element is the count of positives numbers and the second element is the sum of negative numbers.
2 Answers
+ 3
def manipulate_data(alist):
pos, neg = 0, 0
for i in alist:
pos, neg = (pos+1, neg) if i>0 else (pos, neg-i)
return (pos, neg)
https://code.sololearn.com/c0IM0PqgTnSK/#py
0
def manipulate_data( list ):
# your list to accumulate positives and negatives
newList = [ 0, 0 ]
# for every element in the list...
for i in list:
# ... if positive, add one to positive counter
if i >= 0:
newList[ 0 ] += 1
# ... if negative, add one to negative counter
else:
newList[ 1 ] += 1
# return the list where the first element is the count of
# positives, and the second, the count of negatives
return newList



