I have the following function:
def in_loop(i):
global loop_started
if i == '[':
loop_started = True
return [True, 'loop starting']
if loop_started:
if i == ']':
loop_started = False
return [True, 'loop over']
return True
return False
I believe this is returning a tuple that looks like (True, 'loop over') when i is "]". I then try to index into it with
for index, i in enumerate(code):
if in_loop(i):
loop_counter += 1
if in_loop(i)[1] == 'loop starting':
loop_start = index
if in_loop(i)[1] == 'loop over':
loops[f'loop{loop_num}'] = {'start': loop_start, 'end': index}
loop_num += 1
but this raises an error
TypeError: 'bool' object is not subscriptable
Also, code = "+++++[-][-]".
Why is this error being raised when I'm indexing into a tuple?
iis not]too. (Noneis returned)booleanif in_loop(']')[1] == 'loop_over':yet if I don't pass']'asi, i getNoneType object is not subscriptablereturn False/return Truewheniis neither'['or']'