BMWe30
BMWe30

Reputation: 45

string format in python - using a loop to fill

I want to add the data of my changes list to this string --> row

I can do it manually and this works, but I want to do it in a loop. Can someone help?

What I have tried:

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"])

Manually its like this:

        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"])

Upvotes: 3

Views: 232

Answers (1)

Harsha Biyani
Harsha Biyani

Reputation: 7268

You can try:

*changes[key]

instead of

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

Upvotes: 1

Related Questions