
Show HN: How to make your Python code more idiomatic – 25 tips and tricks - jerry-hn
https://github.com/jerry-git/learn-python3#idiomatic-python
======
meowface
Good tips, but all of these really seem to be for Python beginners (even the
ones labelled "intermediate"). Not sure too many Python programmers who use HN
would learn anything new here.

------
svilen_dobrev
This is missing an extremely difficult to grasp thing - namespaces and
binding.
[https://docs.python.org/3/reference/executionmodel.html#nami...](https://docs.python.org/3/reference/executionmodel.html#naming-
and-binding)

    
    
      #example:
      scalers = {}
      for k in range(1,55):
        scalers[k] = lambda x: x*k
      print( scaler[2](3))
      #Above does not work, or worse, sometimes it may work..
      #eo-example
    

And without it, it's all just another procedural indents-instead-of-brackets
thingie

~~~
Doxin
Just doublechecking to make sure I get it, the solution there is to replace
the lambda with something like this right?:

    
    
        lambda x, k=k: x*k

