[Solved] python , changing dictionary values with iteration [duplicate]


for i in range(max_id):
    payload = "{\"text\": R"+str(i)+",\"count\":\"1 \",}"
    print(payload)

Problem with your double quotes.

Output:

{"text": R0,"count":"+i+ ",}
{"text": R1,"count":"+i+ ",}
{"text": R2,"count":"+i+ ",}
{"text": R3,"count":"+i+ ",}
{"text": R4,"count":"+i+ ",}
{"text": R5,"count":"+i+ ",}
{"text": R6,"count":"+i+ ",}
{"text": R7,"count":"+i+ ",}
{"text": R8,"count":"+i+ ",}
{"text": R9,"count":"+i+ ",}

My be you are looking for this one.

for i in range(10):
    payload = "{\"text\": R%s,\"count\":\"1 \",}" %(i)
    print(payload)

5

solved python , changing dictionary values with iteration [duplicate]