[Solved] How to add new item to dictionary in loop using uniquely generated string based on index? (Python)


Your immediate problem is this:

LDates['%s' % ('string%s'['Id'] % i)]

I believe that you mean to access the variable you created earlier. That would require you to use:

LDates[(globals()['string%s' % i])['Id']]

But this whole thing is ill-advised. Why don’t you create a variable where you can access all the data by just passing in the integer i? That would be a list!

Deals = [ sf.deal__c.get(id) for id in x ]

Then set LDates to map Id to due_date__c:

LDates = {d['Id']:d['due_date__c'] for d in Deals}

solved How to add new item to dictionary in loop using uniquely generated string based on index? (Python)