I have this dictionary:
A = {"a": 1, "b":2}
And I want to write, instead of above initialization, a variable instead of 2 that is 4 times a's value that updates if a's value changes.
I cannot do this:
A={"a": 1, "b": 4*A["a"]}
How can I handle this?
‡: Here in my code,
flight = {
"dest": "".join(random.choice(string.ascii_uppercase) for n in xrange(3)),
"from": "".join(random.choice(string.ascii_uppercase) for n in xrange(3)),
"not_available_seats": [],
"available_seats": 50,
"uid": uid,
#"price": 10,
"date": datetime.datetime.now()
}
flight["price"] = lambda: (51 - flight["available_seats"])*10
So when print flight(), I get error.
{}Adoesn't exist yet, soA["a"]has no meaning.A={"a": 1}; A["b"]=4*A["a"];. At this point, A exists, and contains a"a"key with a value.