[Solved] Variable in Dictionary Value String Python


This should do it:

My_DICT = {'Sale_Type' : 'Car', 'Sale_Length' : 5, "Query_String" : ""}
My_DICT['Query_String'] = "select * from Sales where Length > %s" % My_DICT['Sale_Length']

— EDIT —

Considering your input example, you have a list of dictionaries in My_DICT. You could do it like this:

for element in My_DICT:
    element['Query_String'] = "select * from Sales where Length > %s" % element['Sale_Length']

5

solved Variable in Dictionary Value String Python