Skip to content

Instantly share code, notes, and snippets.

@alexgolec
Created September 2, 2019 02:52
Show Gist options
  • Save alexgolec/bff6174c40d3dd8c8e5f919ced4990cc to your computer and use it in GitHub Desktop.
Save alexgolec/bff6174c40d3dd8c8e5f919ced4990cc to your computer and use it in GitHub Desktop.
def convert(conversions, start, end):
'Given a conversion structure, performs a constant-time conversion'
try:
start_root, start_rate = conversions[start]
end_root, end_rate = conversions[end]
except KeyError:
return None
if start_root != end_root:
return None
return end_rate / start_rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment