Fix Python – In Python, when should I use a function instead of a method?

The Zen of Python states that there should only be one way to do things- yet frequently I run into the problem of deciding when to use a function versus when to use a method.
Let’s take a trivial example- a ChessBoard object. Let’s say we need some way to get all the legal King moves available on the board. Do we write ChessBoard.get_king_moves() ….

Fix Python – Passing an integer by reference in Python

How can I pass an integer by reference in Python?
I want to modify the value of a variable that I am passing to the function. I have read that everything in Python is pass by value, but there has to be an easy trick. For example, in Java you could pass the reference types of Integer, Long, etc.

How can I pass an integer into a function by referen….

Fix Python – Which is more preferable to use: lambda functions or nested functions (‘def’)?

I mostly use lambda functions but sometimes use nested functions that seem to provide the same behavior.
Here are some trivial examples where they functionally do the same thing if either were found within another function:
Lambda function
>>> a = lambda x : 1 + x
>>> a(5)
6

Nested function
>>> def b(x): return 1 + x

>>> b(5)
6

Are there advant….

Fix Python – Is there an easy way to pickle a python function (or otherwise serialize its code)?

I’m trying to transfer a function across a network connection (using asyncore). Is there an easy way to serialize a python function (one that, in this case at least, will have no side effects) for transfer like this?
I would ideally like to have a pair of functions similar to these:
def transmit(func):
obj = pickle.dumps(func)
[send obj ac….

Fix Python – Iterating Over Dictionary Key Values Corresponding to List in Python

Working in Python 2.7. I have a dictionary with team names as the keys and the amount of runs scored and allowed for each team as the value list:
NL_East = {‘Phillies’: [645, 469], ‘Braves’: [599, 548], ‘Mets’: [653, 672]}

I would like to be able to feed the dictionary into a function and iterate over each team (the keys).
Here’s the code I’m usi….