dict.__iter__
runs through all the KEYS of the dictionary without giving the values, so for something like:
d = {'a':1, 'b':2, 'c':3}
for element in d:
print(element)
# "a"
# "b"
# "c"
That's why list.extend
is only giving you the keys "errors"
and "filename"
. What would you LIKE it to give you, is the better question? I'm not even sure how that should be expected to work -- maybe a tuple of (key,value)
? To do that, access dict.items()
which will give you a dict_items
object that yields (key,value)
each iteration:
To use the same example:
for element in d.items():
print(element)
# ("a",1)
# ("b",2)
# ("c",3)
Or in your case:
for key,value in cldterr.items():
clderrors.append((key,value))
# or if you want future programmers to yell at you:
# [clderrors.append(key,value) for key,value in cldterr.items()]
# don't use list comps for their side effects! :)
Or simply:
clderrors.extend(cldterr.items())