New course! Every coder should learn Generative AI!
Try a free lesson0
def manipulate_data(n): positives,negatives=[],[] if not isinstance(n,list): raise ValueError return else: for i in n: if i>=0: positives.append(i) if i<0 negatives.append(i) new=[len(positives,sum(negatives)] return new. Someone kindly assist I keep running it in unitests and I keep getting errors. Here's the question:
data structures
2 Answers
+ 1
http://code.sololearn.com/cruBN2hCo7Hv
def manipulate_data(n: list) -> list:
if not isinstance(n,list):
raise TypeError
countPos, sumNeg = 0, 0
for i in n:
if i>=0:
countPos += 1
else:
sumNeg += i
return [countPos, sumNeg]
print(manipulate_data([1, 3, -5, -2, 6, -1]))
0
Here's the question:
Write a function called manipulated_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.