Here is my solution. I tried to write the most "Pythonic" code that I know how to write.
with open('8.txt') as f:
numstring = f.read().replace('\n', '')
nums = [int(x) for x in numstring]
def sub_lists(lst, length):
for i in range(len(lst) - (length - 1)):
yield lst[i:i+length]
def prod(lst):
p = 1
for x in lst:
p *= x
return p
best = max(prod(lst) for lst in sub_lists(nums, 5))
print(best)
, reduce, , , prod() :
from operator import mul
def prod(lst):
return reduce(mul, lst, 1)
, . with, -. , PyPy -, , . with, .
@Steven Rumbalski:
nums = [int(c) for c in open('8.txt').read() if c.isdigit()]
, , , :
with open("8.txt") as f:
nums = [int(ch) for ch in f.read() if ch.isdigit()]
, , , , ; with.