Let's answer this in chronological order (of code execution):
- Line 5,
[False for _ in range(128)]
creates a list of 128 False
values. This is list comprehension, which can be rewritten as follows:
char_set = []
for _ in range(128):
char_set.append(False)
The _
means read the value from the iterator (range
object), and discard it.
- Line 8:
val
is the ord
of a character, meaning a number. char_set[val]
gives us the element at index val
, which is initialized as False
. During your code (line 10, specifically), this might be overwritten to be a True
. The if
statement here checks if the value in that index is True
.
- Line 10: it's not an
else
statement, albeit in this case it works the same. In this code, if the condition in line 8 does not meet, then the code execution flow skips like 9 and "falls through" to line 10, and life goes on. If the condition in line 8 meets (i.e. char_set[val]
is True
), then the line 9 gets executed, and the return
statement ends the function call abruptly while returning False
as its result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…