# Nested typed list does not compile

**URL:** <https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456>\
**Category:** Support: What is this error message?\
**Created:** [July 22, 2022, 6:56pm UTC](https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456 "2022-07-22T18:56:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adetunji-david](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/adetunji-david/32/657_2.png) [@adetunji-david](https://numba.discourse.group/u/adetunji-david)\
**Post date:** [July 22, 2022, 6:56pm UTC](https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456/1 "2022-07-22T18:56:42Z")

</div>

Why would the following code raise a **TypingError: Failed in nopython mode pipeline (step: nopython frontend). list indices must be integers or slices**

```auto
int_list_type = ListType(int64)
@njit
def f():    
    groups = List.empty_list(int_list_type)
    group_id_to_index_map = Dict.empty(key_type=int64, value_type=int64)
    next_index = 0
    for groud_id, item in [(4, 42), (2, 23), (4, 15)]:
        index = group_id_to_index_map.get(groud_id, -1)
        if index == -1:
            group_id_to_index_map[groud_id] = next_index
            groups.append(List([item]))
            next_index += 1
        else:            
            groups[index].append(item)

    return groups

```

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [July 23, 2022, 10:39pm UTC](https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456/2 "2022-07-23T22:39:42Z")

</div>

Can you post a complete minimal sample of what you’re trying to do?

---

<div class="post-metadata">

**Author:** ![adetunji-david](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/adetunji-david/32/657_2.png) [@adetunji-david](https://numba.discourse.group/u/adetunji-david)\
**Post date:** [July 24, 2022, 7:38am UTC](https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456/3 "2022-07-24T07:38:10Z")

</div>

The code I gave is the essence of what I am trying to do. The expected result is a nested typed list of the form [[42, 15], [23]]. This code with the required imports fails to compile. Interestingly, changing the first line to

```auto
groups = []

```

causes no issue.

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [July 25, 2022, 8:09pm UTC](https://numba.discourse.group/t/nested-typed-list-does-not-compile/1456/4 "2022-07-25T20:09:41Z")

</div>

This nested list works for me, perhaps you can adapt it to your code.

````python
int_list_type = numba.typeof(numba.typed.List.empty_list(numba.int64))
nested_list_type = numba.typeof(numba.typed.List.empty_list(int_list_type))

@numba.njit
def append(nested, *args):
    res = numba.typed.List.empty_list(numba.int64)
    for arg in args:
        res.append(arg)
    nested.append(res)

nested_list = numba.typed.List.empty_list(int_list_type)
append(nested_list, 42, 43, 44)
append(nested_list, 1)

print(nested_list)

```
````
