the forxin y statement takes iterable y and assigns a value from it to x per iteration (loop), so what happens is that it’s reassigning chosen_char each loop to the next item from the sentence
(sum([x for x in sentence if x == chosen_char]) would be a quick one-liner, presuming one has downcased the sentence and other input/safety checks)
the
for x in y
statement takes iterabley
and assigns a value from it tox
per iteration (loop), so what happens is that it’s reassigningchosen_char
each loop to the next item from the sentence(
sum([x for x in sentence if x == chosen_char])
would be a quick one-liner, presuming one has downcased the sentence and other input/safety checks)