John - 4 months ago 27

Python Question

So I'm stumped. I want to divide the length of a list by the number values in a dictionary.

`firstNum = 96`

secondNum = 97

list = [1,2,3,4]

dictionary = {'a': 1, 'b': 2}

for x in range(0,13):

firstNum += 1

secondNum += 1

for i in range(firstNum, secondNum):

percent = len(list) / dictionary.get(chr(i))

print(percent)

But I get the error:

TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'

As I understand it, the .get function returns the value, which should be an int? Thanks for any help!

Answer

Going solely by the title - Diving the list by the values in your dictionary

all you need is :

```
>>> l= [1,2,3,4]
>>> d = {'a': 1, 'b': 2}
>>> for i in d.values():
... print len(l)/i
...
4
2
>>>
```

`dictionary.values()`

gives you all the values in your dictionary as a list