Relative Content

Tag Archive for pythonfor-loopif-statementprinting

Repeated result for if statement in python [duplicate]

This question already has answers here: Why does python use ‘else’ after for and while loops? (25 answers) Closed 4 days ago. token_list = [‘lg’, ‘was’, ‘beaten’] defined_words = [‘hand’, ‘leg’, ‘head’, ‘arm’, ‘finger’, ‘wrist’, ‘thigh’] for i in range(0, len(token_list), 1): if token_list[i] in defined_words: print(token_list[i]) break elif token_list not in defined_words: print(‘no injury’) […]