[Tutor] Change dictionary value depending on a conditional statement.
Norman Khine
norman at khine.net
Sun Feb 10 19:55:59 CET 2008
Hello,
Is there a better way to do this:
>>> list = []
>>> total = 0
>>> if total > 0:
... x = {'id': 'name', 'link': 'XX'}
... list.append(x)
... else:
... y = {'id': 'name', 'link': 'YY'}
... list.append(y)
...
I would like to change the key 'link' value depending on the value of
'total' so for example if total == 2, then append x else y to the list.
Thanks
More information about the Tutor
mailing list