Python script itterate through a light group

Hi I would like to write a script that itterates through a light group. The script needs to check which lights are on and based on that change the color of the light(s) that are in state on.
Expand function is available in normal scripts. How does this work in python scripts?