Skip to content
Snippets Groups Projects
Commit 19aace3e authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

rename words_to_int to hashables_to_int

parent 5dceb545
No related branches found
No related tags found
No related merge requests found
......@@ -2,5 +2,5 @@
* `memoize` will release the per-function lock while calling target function
* added `cache_memoize`
* added `words_to_int`
* added `hashables_to_int`
* added covariance to hashable for `satella.coding.typing.K`
Rudimentary data transforms and algorithms
==========================================
.. autofunction:: satella.coding.transforms.words_to_int
.. autofunction:: satella.coding.transforms.hashables_to_int
.. autofunction:: satella.coding.transforms.linear_interpolate
......
__version__ = '2.14.19_a4'
__version__ = '2.14.19_a5'
......@@ -9,7 +9,7 @@ from .merger import merge_series
from .percentile import percentile
from .base64 import b64encode
from .interpol import linear_interpolate
from .words import words_to_int
from .words import hashables_to_int
__all__ = ['stringify', 'split_shuffle_and_join', 'one_tuple',
'merge_series', 'pad_to_multiple_of_length', 'clip',
......
import typing as tp
from satella.coding.typing import K
def words_to_int(words: tp.List[str]) -> tp.Dict[str, int]:
def hashables_to_int(words: tp.List[K]) -> tp.Dict[K, int]:
"""
Assign each word an integer, starting from 0, and return the resulting mapping
Assign each hashable an integer, starting from 0, and return the resulting mapping
:param words: a list of words
:return: a dictionary keyed by words and values are the assigned integers
:param words: a list of hashables
:return: a dictionary keyed by hashable and values are the assigned integers
"""
dictionary = {}
i = 0
......
......@@ -4,14 +4,14 @@ import base64
from satella.coding.transforms import stringify, split_shuffle_and_join, one_tuple, \
merge_series, pad_to_multiple_of_length, clip, b64encode, linear_interpolate, \
words_to_int
hashables_to_int
class TestTransforms(unittest.TestCase):
def test_words_to_int(self):
words = ['a', 'word', 'a']
dct = words_to_int(words)
dct = hashables_to_int(words)
self.assertEqual(len(dct), 2)
self.assertEqual(len(list(dct.values())), 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment