'Python list of dictionaries - for loop

I use this piece of code:

for key, value in test_session_results[test_env].iteritems():
        my_dict = {"test_case": key, "status": value}
        new_dict.update(my_dict)

my_dict always has the different value and I want to append those values to a list, to create a list of dictionaries. I've tried with update but I guess it is not used for this purposes.



Solution 1:[1]

You can create an empty list and append the dictionaries to that list.

a = []

for key, value in test_session_results[test_env].iteritems():
       my_dict = {"test_case": key, "status": value}
       a.append(my_dict)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1