Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Tips for golfing in Python

What general tips do you have for golfing in Python? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Python (e.g. "remove comments" is not an answer).

Please post one tip per answer.

Answer*

Cancel
2
  • 4
    \$\begingroup\$ The "exec" bit goes -9 if you don't need the index. \$\endgroup\$ Commented Oct 8, 2015 at 8:43
  • 1
    \$\begingroup\$ lambda x:g(123456789012,123456789012) can be replaced with lambda x:g(a:=123456789012,a) \$\endgroup\$ Commented Aug 19, 2024 at 0:10