The best way is to try.
In terms of data structure, a way to represent this situation is a dictionary of arrays, which is what groups are. Although, I feel groups were designed for you to know them in advance, but I doubt it if you can have 1000+ of them :p They would still technically work and I think in GDScript the result might be the same, but it's probably an extreme usage if you have other groups to worry about which are not related to that system.
Performance will depend on how often this changes, and how addition, removal and iteration is done. For example, a removal which shifts all following elements is slower than an unordered removal which only swaps the last element to replace the old one.
Due to this, you might also consider dictionary of dictionary, or array of arrays (by using indexes instead of group names).
Also maybe another way is to not use groups at all (or partially), and simply iterate over them all and do the thing you need to do by checking properties dynamically, without bothering to maintain a "database". But without knowing what you are actually doing, it's not easy to find if it's relevant.