python 中的字符串格式 - 使用循环填充

string format in python - using a loop to fill

我想将我的 changes 列表的数据添加到这个字符串 --> 行

我可以手动完成并且这有效,但我想循环执行。有人可以帮忙吗?

我尝试过的:

changes_dict.items {'update':[1], 'history':[0]} # this is also generated generic this is just an example

changes = {'update':["x"], 'history':["-"]} #-> this is dict with lists created generic and always changes

for key, value_list in changes_dict.items():
   row = " *  {:<13} {:<11} {:<10} {:-<1} {:-<1} {:-<1} {:-<1} {:-<1} {:-<1} {:<23}".format(
                ID,
                log_request["date"],
                log_request["author"],
                for item in changes:
                    changes[key][item]
                    
                log_request["description"])

手动是这样的:

        row = " *  {:<11} {:<11} {:<10} {:-<1} {:-<1} {:-<1} {:-<1} {:-<1} {:-<1} {:<23}".format(
            ID,
            log_request["date"],
            log_request["author"],
            changes[key][0],
            changes[key][1],
            changes[key][2],
            changes[key][3],
            changes[key][4],
            changes[key][5],
            merge_request["description"])

你可以试试:

*changes[key]

而不是

for item in changes:
  changes[key][item]