How do I for loop throughout a list of dictionaries inside a tkinter label['text]? How do I for loop throughout a list of dictionaries inside a tkinter label['text]? tkinter tkinter

How do I for loop throughout a list of dictionaries inside a tkinter label['text]?


Not everything ought to be a one liner; in this case, you should probably extract the string formatting from the making of the label; maybe in a function?

def prepare_text_for_label(dict_of_dict):    formatted_strings = []    for d in dict_of_dict:        for k, v in d.items():            token_string = f"[{', '.join([token for token in v])}]"            word_string = f'original: {k}, parsed_results: {token_string}'            formatted_strings.append(word_string)    return '\n'.join(formatted_strings)results =  [{'took':['verb','past']}, {'Adam':['noun','masc']}]print(prepare_text_for_label(results))   # replaced Label with print to show the formatted text.# Label['text'] = prepare_text_for_label(results)

output:

original: took, parsed_results: [verb, past]original: Adam, parsed_results: [noun, masc]