andylei andylei - 1 year ago 106
Python Question

Tips for debugging list comprehensions?

Python list comprehensions are nice, but near impossible to debug. You guys have any good tips / tools for debugging them?

Answer Source

If it's complicated enough that it's not obvious at first glance, unpack it into multiple steps and/or for loops. It's clearly too complicated, and making it more explicit is the easiest way to go about debugging it. Added bonus: you can now step through with the debugger or add print statements!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download