Why don't you initialize `group_all` as a set? And then you just append to this set in the following for loop and then you avoid having to cast the object o a set.