'How to change a global variable from within a for if...?

My program tries to guess if an input number or letter is in a specific string. For that I have this simplified piece of code:

obtained = False

for i in range(6+len(chosen_set)):
  try_let = input("Input something")
  for index, letnum in enumerate(chosen_set):
    if letnum == try_let:
      obtained = True
    else:
      obtained = False
  if obtained:
    # do something
  else:
    # do something else

Say I input the letter "R" and the string I'm testing is XXXRXRX. When the inner for loop goes through its 4th iteration, the variable obtained will be True, and the same will happen for the 6th iteration, but not for the last one, which means the final value of obtained will be False. How should I change my code so that obtained will be True as long as it finds a coincidence regardless of when it finds it? Note that I can't use break in the for loop as soon as it finds a coincidence because the string could have more than one coincidence.



Solution 1:[1]

If you can't use a break, then change the logic of using an explicit True/False boolean as the primary decision factor and make use of a count as well.

For example:

count=0
if letnum == try_let:
    count+=1
if count > 0:
   obtained = True
else:
   obtained = False

Solution 2:[2]

The solution is in @Armin_Montigny's comment. Instructions like

cirStats[j, i] = num;

should, in fact, be written this way:

cirStats[j][i] = num;

that is, without the comma operator.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FlippinBits
Solution 2 zkoza