I am using urllib.urlencode to build web POST parameters, however there are a few values I only want to be added if a value other than None exists
I did this. Hope this help.
apple = 23
orange = 10
a = {
'apple' : apple,
'orange' if orange else None : orange
}
Expected output : {'orange': 10, 'apple': 23}
Although, if orange = None , then there will be a single entry for None:None. For example consider this :
apple = 23
orange = None
a = {
'apple' : apple,
'orange' if orange else None : orange
}
Expected Output : {None: None, 'apple': 23}