Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Add Helge's review suggestions

Co-authored-by: Helge Gehring <helge.gehring@uni-muenster.de>
  • Loading branch information
fbeutel and HelgeGehring authored Dec 10, 2020
1 parent a908679 commit 0ac9fd7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions gdshelpers/helpers/small.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ def id_to_alphanumeric(column, row):
return int_to_alphabet(row) + str(int(column))


def parse_alphanumeric(text):
def alphanumeric_to_id(text):
"""
Do the reverse of `id_to_alphanumeric`.
Returns the (column, row) tuple.
:return: (column, row) tuple.
"""
regex = "([A-Z]*)[^0-9]*([0-9]*)"
m = re.match(regex, text.strip(), re.I)
regex = "([A-Z]*)([0-9]*)"
m = re.match(regex, text, re.I)
letters, number = m.group(1), int(m.group(2))
letter_num = 0
for i in range(len(letters)):
letter_num += (ord(letters[i]) - 64) * (26 ** (len(letters) - i - 1))
letter_num = sum((ord(letter) - ord('A') + 1) * 26 ** i for i, letter in enumerate(letters[::-1]))
return number, letter_num - 1


Expand Down

0 comments on commit 0ac9fd7

Please sign in to comment.