for i in range(3):     locals()["group"+str(i)] = self.getGroup(selected, header+i) 

Read more of this post