@brockdyer03’s solution is certainly a more elegant method and I would assume both more robust and giving better results. I am curious how it will turn out.
For completeness I still wanted to share some color pairings the python code made:
#f0f0f0 #3fbfbf (H)
#7f7f7f #8cd8d8 (C)
#3050ff #ffd700 (N)
#ff0d0d #00feff (O)
#b2ffff #ff0000 (F)
#ff8000 #65b2ff (P)
#ffff30 #0000ff (S)
#1ff01f #ee10ee (F)
They are not super appealing in my opinion, for example the H and C contrast colors are light blue but I would prefer them to just be greyscale.