def pure(n): return n == 0 or (n > 0 and (pure(n-12) or pure(n-19) or pure(n-28))) # 2 3 5 def dissonance(chord): i = 0 while reduce(lambda a,b: a or not pure(b+i), chord, False): i += 1 return i notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "B#"] for i in xrange(12): print "C %2s"%notes[i], "="*dissonance([0,i]) print print "C E G", "="*dissonance([0,4,7]) C C C C# =============================================== C D ==================================== C D# ============================ C E ======================== C F =================== C F# ================================================== C G ============ C G# ============================ C A =================== C A# ============================ C B ==================================== C E G ========================