I'll let the code speak for itself, as I've been heaving a headache over this for a while now. Below is a test I've put together to simplify the investigation.
# This is a python file containing a dictionary of tuples with RGB colours (R, G, B)
import random
colours = {
'black': (0, 0, 0,),
'white': (255, 255, 255,),
'red': (255, 0, 0,),
'green': (0, 255, 0,),
'blue': (0, 0, 255,),
'yellow': (255, 255, 0,),
'purple': (255, 0, 255,),
'brown': (139, 69, 19,),
'orange': (255, 165, 0,),
'cyan': (0, 255, 255,),
}
print('1', colours)
print('2', list(colours))
print('3', ((list(colours)).remove('black')))
print('4', random.choice((list(colours)).remove('black')))
print('5', colours[random.choice((list(colours)).remove('black'))])
These test print statements print respectively:
1 {'black': (0, 0, 0), 'white': (255, 255, 255), 'red': (255, 0, 0), 'green': (0, 255, 0), 'blue': (0, 0, 255), 'yellow': (255, 255, 0), 'purple': (255, 0, 255), 'brown': (139, 69, 19), 'orange': (255, 165, 0), 'cyan': (0, 255, 255)}
2 ['black', 'white', 'red', 'green', 'blue', 'yellow', 'purple', 'brown', 'orange', 'cyan']
3 None
Traceback (most recent call last): File "C:/Users/macja/PycharmProjects/pygame_sentdex_tutorial/colours.py", line 21, in print('4', random.choice((list(colours)).remove('black'))) File "C:\Users\macja\AppData\Local\Programs\Python\Python37-32\lib\random.py", line 259, in choice i = self._randbelow(len(seq)) TypeError: object of type 'NoneType' has no len()
So as you can see, it all seems to come down at .remove('black') I'm not particularly interested in a workaround, that's easy. I'd like to understand what happened to cause this problem, as I'm just learning python.