ARTICLE AD BOX
I'm asking this here, as it's an... odd question, and I'm not even sure how to phrase this as a "Google" query. I'll try to be brief.
I'm just teaching myself Python. I've used BASIC and Javascript, so it's not completely foreign to me, but I've got a situation, I know how to do what I want, but it's an "Isnt' there a better way" situation.
I've got a 2 dimensional array, for sake of simplicity, we'll call it
a[x]
which we'll say has 30 variables in it. ( a[0] through a[29]). From this array, I want to take some of these, and do some processing with them. Let's say for example I want to take a[5], a[12], a[17] and a[24], and do an "if/then" with each. Now I know I could
if a[5] = "A"
count1 = 1
else:
count2 = 1
if a[12] = "A"
count1 = count1 + 1
else:
count2 = count2 + 1
and so on, for each instance. I know if I were doing ALL of them, or even every other or some consistent order, I could use a for loop, and step through each each one. But is there an easier way, than a chain of IF/THEN statements, with a basically "random" list like this? I'd thought about a "list" (not sure if that's the correct term), and I'm guessing on the syntax, but basically
t=[5,12,17,24]
and then some form of
if a[t] = "A"
count1 = count1 + 1
else:
count2 = count2 + 1
The IF statements work for 2 or 3 instances, but if you're dealing with a dozen or more, it'd seem like there must be a better way to accomplish this.
Thanks in advance.
