How can i prevent from adding a list into a list when using setdefault with a list type definition.
output = dict()
output.setdefault("key", []).append(["name", 1])
print output
>>> {'key': [['name', 1]]}
Desired output
>>> {'key': ['name', 1]}
You want .extend
rather than .append
- the former adds a list of items to a list, the latter adds a single item - so if you pass it a list, it adds the list as a single subitem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With