Created
April 9, 2019 19:13
-
-
Save noisywiz/4b4f993e77b26949838851b1cb18fa6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(file_name, search_list): | |
counter = 0 | |
def handle(state): | |
# print(state) | |
nonlocal counter | |
if state.isdigit(): | |
integer_state = int(state) | |
if integer_state in search_list: | |
# print('!!!') | |
del search_list[integer_state] | |
counter += 1 | |
# print(search_list) | |
with open(file_name) as f: | |
i = 0 # file symbol | |
state = '' | |
while True: | |
symbol = f.read(1) | |
if symbol in (' ', '\n') or symbol == '' and i != 0: | |
handle(state) | |
state = '' # clear current state | |
else: | |
state = state + symbol | |
# The End | |
if symbol == '' and i != 0: | |
break | |
i += 1 | |
return counter | |
print(main('test.txt', [0,1,2,3,4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment