# Access items in a list

**URL:** <https://community.riskscape.org.nz/t/access-items-in-a-list/212>\
**Category:** Community\
**Created:** [5 March 2025 21:36 UTC](https://community.riskscape.org.nz/t/access-items-in-a-list/212 "2025-03-05T21:36:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPowell](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@JPowell](https://community.riskscape.org.nz/u/JPowell)\
**Post date:** [5 March 2025 21:36 UTC](https://community.riskscape.org.nz/t/access-items-in-a-list/212/1 "2025-03-05T21:36:30Z")

</div>

The output of my python function seems to be a list. If I try to access it using the usual . notation inside a select riskscape gives me an error

```auto
- Property consequence of {..., consequence=>List[{NIWA_Damage_Ratio=>Floating}],...} is not a struct - was List[{NIWA_Damage_Ratio=>Floating}]

```

How can I fix this?

---

<div class="post-metadata">

**Author:** ![timbeale](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@timbeale](https://community.riskscape.org.nz/u/timbeale)\
**Post date:** [5 March 2025 23:09 UTC](https://community.riskscape.org.nz/t/access-items-in-a-list/212/2 "2025-03-05T23:09:02Z")

</div>

Hi John,

There’s a couple of different approaches, depending on what exactly you want to do.

Currently you have a list of structs, which makes things a little complicated. If you just wanted the mean/max/percentile value from the list, then you could change the `consequence` into a list of floats, and then use list aggregation. This would look something like:

```auto
mean(map(consequence, x -> x.NIWA_Damage_Ratio)) as mean_DR

```

You could probably then simplify things further by changing the return type of your Python function to be use float instead of a struct. Then the pipeline code would simply be:

```auto
mean(consequence) as mean_DR

```

If you wanted to pull a specific index out of the list, then it’s a little convoluted, but you could do something like this to pull out the first item in the list:

```auto
list_to_columns(consequence, { number: 5, prefix: 'item' }).item1.NIWA_Damage_Ratio

```

Here, the `number` is the max length that you expect the list to be.

The other option is to use the `unnest()` step to unnest the list, and then you can process each item in the list individually. Be aware that this will duplicate everything else in that row of data though, e.g. if the list is 10 items long, then you will end up with 10 copies of the input exposure after you unnest the list. For example, if you’re using all-intersections sampling and processing each item in the list then you may want to [scale the losses](https://riskscape.org.nz/docs/intermediate/modelling.html#scaling-losses) for each item in the list.

Hope that helps,  
Tim

---

<div class="post-metadata">

**Author:** ![JPowell](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@JPowell](https://community.riskscape.org.nz/u/JPowell)\
**Post date:** [6 March 2025 19:57 UTC](https://community.riskscape.org.nz/t/access-items-in-a-list/212/3 "2025-03-06T19:57:39Z")

</div>

Thanks Tim there is four items in the list that python is returning and this code runs

```auto
        round(mean(map(consequence, x -> x.NIWA_Damage_Ratio))) as NDR,
        round(mean(map(consequence, x -> x.NIWA_Repair_Cost))) as NRC,
        round(mean(map(consequence, x -> x.Damage_Ratio))) as DR,
        round(mean(map(consequence, x -> x.Repair_Cost))) as RC,

```

but I don’t love it. I will look into adjusting the python code
