I've been tasked with finding the distance between two letters in the alphabet. Below is my solution. My main concerns are if there is any shorter way to do this, and if there are any edge cases I'm not. Thanks!
import string LETTERS = string.ascii_lowercase def shortest_distance_between_letters(a: str, b: str) -> int: """ Returns the shortest distance between letters. This include wrapping around the letters. See below examples for clarification. >>> call('a', 'c') 2 # 'a' -> 'b' -> 'c' >>> call('b', 'x') 4 # 'b' -> 'a' -> 'z' -> 'y' -> 'x' """ if a == b: return 0 first = a if ord(a) < ord(b) else b second = b if ord(b) > ord(a) else a return min( LETTERS.index(second) - LETTERS.index(first), (len(LETTERS) - LETTERS.index(second)) + LETTERS.index(first) )