Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to print python dictionary in IDLE

I am trying to print a dictionary value after deleting few key-value. Below code works in Pycharm but throwing error when i execute the same in IDLE it throws error. please, guide.

**users={'John':'Active',
       'Joseph':'Inactive',
       'Reeta':'Inactive'}
for del_user, status in users.copy().items():
    if status=='Inactive':
        del users[del_user] 
        print(del_user)
print(users) **

PyCharm Output

IDLE output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

users={'John':'Active',
       'Joseph':'Inactive',
       'Reeta':'Inactive'}
for del_user, status in users.copy().items():
    if status=='Inactive':
        del users[del_user] 
        print(del_user)
print(users)

Above code is working fine on IDLE.
Crosscheck that you are giving proper indentation and not adding **.
If might cause if you copy the code from somewhere.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading