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

3

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

我可以手动完成它,这个方法可行,但我希望用循环来实现。有人能帮忙吗?

我尝试过以下方法:

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_dict 包含什么内容? - Harsha Biyani
1个回答

1
你可以尝试:

*changes[key]

替代

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

抱歉,那是我的错,changes是一个字典,就像changes_dict一样,只是有一个新的映射1=X,0=-。 - BMWe30

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接