I have a program which contains a list, and in this list are either strings or objects of a class A
. A sample list looks something like this:
['foo', 'bar', A('m',2), 'asdf', A('c', 2)]
As you can see, the class accepts a character and an integer value for its constructor.
I'm trying to write a conditional such that it finds the number of occurrences of the function with a specific first parameter. For instance, I want to find how many items in the list are of the form A('m', x)
where x
is any integer, which in this case would be 1.
How could I write an if statement to check for these elements? For now, I have:
if (listEle = A(desiredCharacter, any(1,2,3,4,5,6,7,8,9)))
Is this correct, and if yes, is there an easier way to do this?