diff --git a/subjects/devops/string_tokenizer_count/README.md b/subjects/devops/string_tokenizer_count/README.md index df00a4879..205393121 100644 --- a/subjects/devops/string_tokenizer_count/README.md +++ b/subjects/devops/string_tokenizer_count/README.md @@ -30,10 +30,26 @@ $ - The `re` module can be used to remove non-alphanumeric characters. -- The `collections` module can be used to count the words. +- The `Counter` class of the `collections` module can be used to count the words. - The `operator` module can be used to sort the dictionary alphabetically by word. +Here is an example of how to sort a dictionary in python, using a test.py script: + +```python +dictionary = {'a': 5, 'c': 1, 'b': 3} +sorted_dict = dict(sorted(d.items(), key=lambda item: item[1])) +print(sorted_dict) +``` + +And its output: + +```console +$ python3 ./test.py +{'c': 1, 'b': 3, 'a': 5} +$ +``` + ### References - [`re` module](https://docs.python.org/3/library/re.html)