2021年1月18日星期一

How to susbstuite the string from the dictionary values

My parent dictionary is below

d =   [{"code":1, "description":"This is only one %s", "name":"Hello"},  "code":2, "description":"This %s has one more %s", "name":"World"}]  

My input {'code':1, 'details':['A']}

Expected out {"description":"This is only one A", "name":"Hello"}

My input {'code':2, 'details':['A','B']}

Expected out {"description":"This A has one more B", "name":"World"}

  • There is %s in the description
  • it has to replace by the values inside the details key
https://stackoverflow.com/questions/65785326/how-to-susbstuite-the-string-from-the-dictionary-values January 19, 2021 at 12:05PM

没有评论:

发表评论