[Tutor] Question about about PEP8

Manprit Singh manpritsinghece at gmail.com
Tue Jul 7 02:45:01 EDT 2020


Dear all,

As i have read in PEP 8 , it suggests not to compare values to true or
false using "==".  Secondarily it is also written in python documentation
that empty collections and sequences (list, tuple set and dict) are
considered false .

So I just need to know if the code written by me in two cases is correct or
not:


*Case 1)  I have to update the dict if it is empty using an if statement  .
*

e = {}                          # empty dict
if not e:
    e.update(A=3)        # will update the dict if it is empty otherwise
not
print(e)

*case 2 ) I have to remove and print each item of dict in LIFO order :*

d = {"A":9, "B":6, "C":3}
while d:
    x = d.popitem()
    print(x)

Regards
Manprit Singh


More information about the Tutor mailing list