Question: So my function should open a file and count the word length and give the output. For example,

many('sample.txt')

Words of length 1: 2

Words of length 2: 6

Words of length 3: 7

Words of length 4: 6

My sample.txt file contains:
This is a test file. How many words are of length one?
How many words are of length three? We should figure it out!
Can a function do this?

My coding so far,

```
def many(fname): infile = open(fname,'r')
text = infile.read()
infile.close()
L = text.split()
L.sort
for item in L:
    if item == 1:
        print('Words of length 1:', L.count(item))

```

Can anyone tell me what I'm doing wrong. I call the function nothing happens. It's clearly because of my coding but I don't know where to go from here. Any help would be nice, thanks.

Answer: 
You want to obtain a list of lengths (1, 2, 3, 4,... characters) and a number of occurrences of words with this length in the file.

So until `L = text.split()` it was a good approach. Now have a look at *dictionaries* in Python, that will allow you to store the data structure mentioned above and iterate over the list of words in the file. Just a hint...
Maybe also this: 

```
>>> s
'This is a test file. How many words are of length one? How many words are of length three? We should figure it out! Can a function do this?'
>>> {x:[len([c for c in w ]) for w in s.split()].count(x) for x in [len([c for c in w ]) for w in s.split()] }
{1: 2, 2: 6, 3: 5, 4: 6, 5: 4, 6: 5, 8: 1}

```