Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Common Python Mistakes

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for D. Yu D. Yu
February 25, 2014

Common Python Mistakes

Originally named "Common Newbie Mistakes in Python" then I realized I still make these mistakes. Wait. I guess that still makes me a newbie.

First presented at PizzaPy - Feb 25, 2014.

Avatar for D. Yu

D. Yu

February 25, 2014

More Decks by D. Yu

Other Decks in Programming

Transcript

  1. Checking if a list is empty. # l is a

    list if l != None and len(l) > 0 : pass
  2. Indices in a list. for i in l: print i

    # If you really want indices: for i, item in enumerate(l): print i, item
  3. Iterating over a dict and deleting items. for k, v

    in d.iteritems(): if k == x: del d[k]
  4. Iterating over a dict and deleting items. You can’t delete

    items in a dict while iterating over it. This causes a RunTimeError in Python. Sometimes leads to unpredictable behavior in other languages.
  5. Iterating over a dict and deleting items. for k in

    d.keys(): if d[k] == x: del d[k]
  6. END