[Solved] str.find == -1 but the string cant pass the if condition


You’re decrementing i twice: once inside the if-statement, once every time in the while loop. Hence, when the if statement evaluates to True, i will be decremented by 2 in total, and you will skip past some values of i.

A quick test shows that, indeed, i == 194 is skipped: i jumps from 195 to 193. Thus, the particular comparison you mention is never evaluated, because i is never 194.

This is easy to evaluate and debug yourself: just use print(i) in every loop, just before the if-statement, and see how it changes.


In addition, you state your input is a dict. It is, in fact, a perfectly valid JSON file, and you can (should) read it as follows:

import json

with open(sys.argv[1]) as f:
    dic = json.load(f)

No need to use eval, no need to use false = False; null = ""; true = True. These lines can only create confusion and (severe) bugs, and should be removed. Note, by the way, that null (JSON) is transformed to None in Python, not "" (the empty string).

4

solved str.find == -1 but the string cant pass the if condition