JetBlackT
JetBlackT

Reputation: 21

Python counter and values

I'm trying to get the assert statements below to return True

assert len_multi(Counter('aabbcc')) == 6
assert len_multi(Counter('aaa')) == 3
assert len_multi(Counter()) == 0

What I initially wrote is

from collections import Counter
def len_multi():
    myList = ('aabbcc')
    multiList = Counter(myList)
    multiA = sum(multiList.values())
    print(multiA)
len_multi()

So I think what I'm doing is wrong is including another Counter within the function. So I'm applying a Counter to a Counter?

So I tried this, but still can't get of the counter?

multiA = ('aabbcc')
print(sum(Counter(multiA).values()))

I think what I need to do is assign the value given in the assert statement to a pre-defined variable?

Any pointers would be super helpful.

Upvotes: 1

Views: 92

Answers (1)

i dont actualy understand what you tryna do but here i correct your code:

from collections import Counter

def len_multi(multiList):
    multiA = sum(multiList.values())
    return(multiA)

assert len_multi(Counter('aabbcc')) == 6 #True program goes on
assert len_multi(Counter('aaa')) == 0    #False you get an assertion error

Upvotes: 1

Related Questions