Decoding data from a MIDI controller as eight buttons
Use a dict for lookups
When doing lookups, Python provides an associative array data structure called a dict.  Your stacked ifs can be cleanly written as a dict lookup like:
button_text = {
    (&quot;B&quot;, &quot;1&quot;, &quot;6&quot;): &quot;Button1&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;7&quot;): &quot;Button2&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;8&quot;): &quot;Button3&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;9&quot;): &quot;Button4&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;A&quot;): &quot;Button5&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;B&quot;): &quot;Button6&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;C&quot;): &quot;Button7&quot;,
    (&quot;B&quot;, &quot;1&quot;, &quot;D&quot;): &quot;Button8&quot;,
}

print(button_text[data[-8], data[-5], data[-4]])