I'd also suggest to use a context manager (the with keyword) for clean opening and closing of files.
with
Part 1:
with open("input.txt") as f: freq = sum(int(i.strip()) for i in f) freq
Part 2:
from itertools import cycle with open("input.txt") as f: freqs = [int(i.strip()) for i in f] seen = set() current = 0 for f in cycle(freqs): if current in seen: print(current) break else: seen.add(current) current += f
Also: "Hey checkout my Github Repo!"
True! Always forget to do that since I really only do file handling for code challenges at this point.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'd also suggest to use a context manager (the
with
keyword) for clean opening and closing of files.Part 1:
Part 2:
Also: "Hey checkout my Github Repo!"
True! Always forget to do that since I really only do file handling for code challenges at this point.