dhp.transforms package

Module contents

dhp transforms library

dhp.transforms.chunk_r(buf, chunk_size)

starting from the right most character, split into groups of chunk_size.

>>> chunk_r('abcdefg', 3)
['a', 'bcd', 'efg']
Parameters:
  • buf (str) – a string or object that can be stringified
  • chunk_size (int) – the maximum size of the groups
Returns:

chunk_sized strings

Return type:

list

dhp.transforms.filter_dict(dictionary, keys)

filter a dicitionary so it contains only specified keys.

>>> old = {'foo': 0, 'bar': 1, 'baz': 2}
>>> filter_dict(old, ['bar', 'baz', 'missing'])
{'bar': 1, 'baz': 2}
Parameters:
  • dictionary (dict) – the dictionary to filter out unwanted keys/vals
  • keys (list) – the list of keys to return in the resultant dicitionary
Returns:

the resultant dictionary with only the specified keys

Return type:

dict

dhp.transforms.int2word(ivalue)

return the integer value as word(s)

>>> int2word(12)
Twelve
>>> int2word(237)
Two Hundred Thirty Seven
Parameters:ivalue (int) – the integer to be converted
Returns:The spelled out value of ivalue
Return type:str
dhp.transforms.to_snake(buf)

pythonize the camelCased name contained in buf

>>> to_snake('camelCase')
camel_case
Parameters:buf (str) – the camelCased name to transform
Returns:the pythonized version of the camelCased name
Return type:str