Monday, September 8, 2008

new utils functions

A lot had been added to the utils package of late.

-nullDict: make a dictionary with all the values of None and the keys from a given iterable.
Note this is the essential work in making a unique list.

-time2datetime: make a datetime instance from a time instance
"""convert time (from time module)
to datetime from datetime module
"""

-dict2optStr: makes handy option string for use when calling external programs
"""transform a dictionary to a command line options string.
e.g. {'-o': 'short', '-x': None} => "-o short -x"
"""

-iterCount
"""count number of times each value is seen in iterable.
return dict((value,count),...)
"""

-addDict
"""Given 2 dictionaries with values that support addition
numbers, strings, lists, tuples returns a dictionary
with shared keys' vaules which are the sum of the like-keyed values.
Unique keys in d1, d2 are also in the result.
"""