If I try:
mi_list = ['three', 'small', 'words'] mi_set = set(mi_list) mi_set.remove('small') print mi_set
I get:
set(['three', 'words'])
which is what I expect. Whereas If I try:
mi_list = ['three', 'small', 'words'] mi_set = set(mi_list).remove('small') print mi_set
I get:
None
Why?
I suspect there’s a clue in that if I try to remove an element that isn’t present – eg ‘big’ – an error gets reported:
KeyError: 'big'
set.removereturns nothing (None).Your code assigns the return value of
set.removeto the variablemi_set. Therefore, mi_set is None.