Skip to content

Instantly share code, notes, and snippets.

@rugheid
Created March 14, 2018 12:28
Show Gist options
  • Save rugheid/5637800841d3dac08e3a12c90815856f to your computer and use it in GitHub Desktop.
Save rugheid/5637800841d3dac08e3a12c90815856f to your computer and use it in GitHub Desktop.
def read_format(f):
line = input().split()
tokens = []
for i in range(len(f)):
token, line = f[i](line, i == len(f)-1)
tokens.append(token)
return tokens
def _parse_f(f):
return lambda words, last: (f(words[0]), words[1:])
getal = _parse_f(int)
kommagetal = _parse_f(float)
def tekst(words, last):
if last: return " ".join(words), []
return words[0], words[1:]
i, = read_format([getal])
print(i)
j, s = read_format([kommagetal, tekst])
print(j, s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment