Home > Back-end >  How to assign the two different counts of something to a same variable?
How to assign the two different counts of something to a same variable?

Time:01-06

I have the no. of A's to count but in one of cell of an excel its 'A' & in some cells its 'A '

So, If the cell has 'A' I want my code to count no of 'A' and store in count_a, else if my cell has 'A ' I also want that to be counted and stored in same variable count_a.

def config(status: []) -> None:
    global count_a
    count_a = status.count('A' or 'A ')

This code somehow seems to be not working, Thanks for the help in advance

CodePudding user response:

It is not working because status.count('A' or 'A ') does not even close what you think it does. It does not count "A"s and "A "s. It counts "True"s, because first the expression 'A' or 'A ' is evaluated, which results in True and then count() counts.

You have to count them separately:

count_a = status.count('A')
count_a  = status.count('A ')

or

count_a = status.count('A')   status.count('A ')
  • Related