I'm trying to make use of Yield and decided to try out flattening a dictionary but I think I missed a detail.
def flatten(d):
for k, v in d.items():
if isinstance(v, dict):
flatten(v)
else:
yield v
di = {"a" : 1,
"b" : {
"c": 2,
"d": 3,
"e": {
"f":4,
6:"a",
5:{"g" : 6},
}
}}
for i in flatten(di):
print(i)
This code only returns the number 1.
I was under the impression that my flatten function would keep rolling past the first Yield, unlike Return.