Fix Python – Python argparse: default value or specified value

I would like to have a optional argument that will default to a value if only the flag is present with no value specified, but store a user-specified value instead of the default if the user specifies a value. Is there already an action available for this?
An example:
python script.py –example
# args.example would equal a default value of 1
pytho….

Fix Python – Named tuple and default values for optional keyword arguments

I’m trying to convert a longish hollow “data” class into a named tuple. My class currently looks like this:
class Node(object):
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right

After conversion to namedtuple it looks like:
from collections import namedtuple
Node = named….

Fix Python – How does collections.defaultdict work?

I’ve read the examples in python docs, but still can’t figure out what this method means. Can somebody help? Here are two examples from the python docs
>>> from collections import defaultdict

>>> s = ‘mississippi’
>>> d = defaultdict(int)
>>> for k in s:
… d[k] += 1

>>> d.items()
[(‘i’, 4), (‘p’, 2), (‘s’, 4), (‘m’, 1)]

and
>>> s = [(‘….