How to assign the two different counts of something to a same variable?

Question:

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

Asked By: abhishekravoor

||

Answers:

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 ')
Answered By: Psytho
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.