As you can see in the screenshot, I have a layer with a lot of empty categories (0 features). Is it a way to automatically remove this categories from TOC? To do it manually, it is complicated cause I have a lot of empty categories.
EDIT @Mayo: Are you sure it works in this case? See second capture. In case, value is the same as legend, it works... but in the capture, you'll see it is different. And after using the python code, the category is empty.