Home > OS >  Does python count deleted items?
Does python count deleted items?

Time:11-16

WF={"Angel Falls":3211.7, "Tugela Falls":3110.2, "Three Sisters Fall":2998.5, "Olo'supena Falls":2953.3, "Yumbilla Falls":2940}

Referring to above, when I have delete the "Angel Falls" using code below:

Waterfall = dict(WF)
del Waterfall["Angel Falls"]
print(len(WF))

It will give me an answer of 5. Why it is not 4 instead since I have deleted one item in the dict?

CodePudding user response:

It's because Waterfall = dict(WF) create a copy of WF dictionary.

So you have 2 objects :

  • WF
  • Waterfall

Your remove operation is on Waterfall dict object.

Then you print the WF dict object which has not changed.

Print Waterfall to view change.

  • Related