Skip to content

Instantly share code, notes, and snippets.

@marekborowiec
Created April 2, 2020 21:30
Show Gist options
  • Save marekborowiec/94163ed20303d9ab69ffeeacc27d6294 to your computer and use it in GitHub Desktop.
Save marekborowiec/94163ed20303d9ab69ffeeacc27d6294 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
with open('miltons-numbers') as f:
records = f.readlines()
for record in records:
if '.' not in record:
first, sep, tail = record.partition('-')
last, sep2, tail2 = tail.partition(' ')
digits = len(last)
to_prefix = first[:len(first) - digits]
start = int(first)
end = int(to_prefix + last) + 1
for i in range(start, end):
if len(str(i)) < len(first):
print(str(i).zfill(len(first)))
else:
print(str(i))
else:
to_prefix_and_first, sep, tail = record.partition('-')
last, sep2, tail2 = tail.partition(' ')
first_lst = to_prefix_and_first.split('.')
first = first_lst[-1]
to_prefix = '.'.join(first_lst[0:-1])
start = int(first)
end = int(last) + 1
for i in range(start, end):
print(to_prefix + '.' + str(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment