How would I go about making a special singleton, like None
? (I'm new to python.)
I want to be able to do this sort of thing:
def create_mutations(d):
return [
Mutation(c, v)
if v is not CellAction.Delete else
Mutation(c, isDelete=True)
for (c, v) in d
]
Used like this:
create_mutations({'a': 5, 'b': None, 'c': CellAction.Delete})
This would create a list containing three mutations, meaning "set a
to 5
, set b
to None
, and delete c
."
The point is that in the definition of create_mutations
I cannot use ... if v is not None else ...
because then there is no distinction between "set b
to None
" and "delete b
."
I can clarify if the question isn't clear.