# Group list in FISH and Python

**URL:** <https://forum.itascainternational.com/t/group-list-in-fish-and-python/802>\
**Category:** Uncategorized\
**Created:** [October 28, 2022, 7:31pm UTC](https://forum.itascainternational.com/t/group-list-in-fish-and-python/802 "2022-10-28T19:31:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juantello](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@juantello](https://forum.itascainternational.com/u/juantello)\
**Post date:** [October 28, 2022, 7:31pm UTC](https://forum.itascainternational.com/t/group-list-in-fish-and-python/802/1 "2022-10-28T19:31:41Z")

</div>

I’m trying to get the full list of groups that exist in the model, both in Fish and in Python, so I can check how many zones there are in it and delete empty groups. What is the recommended way of doing this? Thank you in advance,

---

<div class="post-metadata">

**Author:** ![jmswdmn](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@jmswdmn](https://forum.itascainternational.com/u/jmswdmn)\
**Post date:** [October 29, 2022, 10:09am UTC](https://forum.itascainternational.com/t/group-list-in-fish-and-python/802/2 "2022-10-29T10:09:31Z")

</div>

You can export a list of the group for each zone in the model using the [file.all](http://docs.itascacg.com/flac3d700/common/fish/doc/fish_manual/fish_fish/file_utilities/fish_file.all.html?highlight=file%20all) command as described in forum post [here](https://forum.itascainternational.com/t/top-tips-and-hidden-gems/202/6). e.g.

```auto
[file.all("test.txt","text") = zone.group(::zone.list)]

```

However, you might also need to consider the slots of your groups, and therefore might want an output file with more structure, which you can then manipulate? If so, something like the following might get you started in python:

```auto
import itasca as it
import json
it.command("python-reset-state false")
it.command("""
model restore "test"
""")

output_dict = {}

for z in it.zone.list():
        slot_def = z.group()
        slot_example_1 = z.group("Example 1")
        slot_example_2 = z.group("Example 2")
        output_dict[z.id()] = {
            "slot = default" : slot_def,
            "slot = 1" : slot_example_1,
            "slot = 2" : slot_example_2
            }
    
output_file = "test.json"
with open(output_file, 'w') as fout:
    json.dump(output_dict, fout)

```

---

<div class="post-metadata">

**Author:** ![Moo](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Moo](https://forum.itascainternational.com/u/Moo)\
**Post date:** [November 1, 2022, 8:44pm UTC](https://forum.itascainternational.com/t/group-list-in-fish-and-python/802/3 "2022-11-01T20:44:56Z")

</div>

juantello:  
There is a hidden command in the code - GROUP LIST -COUNT  
This lists of summary of (for examples) the total number of zones, the number of zones with a group in a given slot, and the number of zones using a given group/slot combination.  
This could be logged to a file and then imported back for processing either in FISH or Python.

I’m a bit confused about the idea deleting groups however. Groups cannot be deleted, but empty groups cause no overhead so there is no real reason to.
