Question: I have the lists below and I need to assign the strings from fruit list into stall list depending on their length. 

```
fruit = ['an', 'king', 'be', 'brave']
stall = [[],[],[],[]]

```

So the result should be like this

```
stall = [[ ],['an', 'be'],[ ],['king', 'brave']] 

```

I’ve tried so many ways and even attempted to create a new list to see where I am going wrong but not even this is populating anything. Can someone please point me where I am going wrong? I've never had to append to list of lists before.

```
i = 0
s = stall[i]
for j in fruit:
    if(len(j)) == i+1:
        s.append(j)
        i += 1
print(stall)

```

Answer: 
I'm not sure if classifying *king* and *brave* together, as your question does, was deliberate or not. I'm assuming deliberate.

```
fruit = ['an', 'king', 'be', 'brave']
stall = [[],[],[],[]]
for f in fruit:
        stall[min(len(f),4)-1].append(f)

```

This will give you

```
>>> stall
[[], ['an', 'be'], [], ['king', 'brave']]

```
One way could be following. First you get the size of the empty list `stall` from the dimensions of the largest string in your `fruit`. Then you simply append the fruits to the corresponding position in your nested lists.

The `len(f)-1` is used because the indexing in python starts from 0. 

```
fruit = ['an', 'king', 'be', 'brave']
stall = [[] for _ in range(len(max(fruit, key=len)))]

for f in fruit:
    stall[len(f)-1].append(f)

print (stall)
# [[], ['an', 'be'], [], ['king'], ['brave']]

```