This is my first question on Stack Overflow.
I want to add a new dictionary at the end of an existing list with multiple dictionaries (see example below):
travel_log = [
{
"country": "France",
"visits": 12,
"cities": ["Paris", "Lille", "Dijon"]
},
{
"country": "Germany",
"visits": 5,
"cities": ["Berlin", "Hamburg", "Stuttgart"]
},
]
new_country = {
"country": country,
"visits": int(visits),
"cities": list_of_cities,
}
new_country
needs to be added to the list of travel_log
, but for a certain reason if I write:
travel_log += new_country
It does not work, while
travel_log.append(new_country)
will give the correct result.
I thought until now that the +=
operator could be used in lists quite easily, but I am now a bit confused. Thank you in advance for your answers.
travel_log += [new_country]