Another (sort of crazy) implementation using a dictionary comprehension:
In case anyone is looking for this, someone recently asked me about using note names instead of midi pitches, and I wrote this insane dictionary comprehension that works:
named_notes = {
f"{letter}{alteration}{octave}": [9, 11, 12, 14, 16, 17, 19]["ABCDEFG".index(letter.upper())] + \
12 * octave + [-1, 0, 1][("b", "", "#").index(alteration)]
for letter in "ABCDEFGabcdefg"
for alteration in ("b", "", "#")
for octave in range(0, 9)
}
print(named_notes["c4"])
print(named_notes["D#5"])
print(named_notes["Eb3"])