src.ch01.practice package¶
Submodules¶
src.ch01.practice.p1_pig_latin module¶
Takes a word as input and returns its Pig Latin equivalent.
-
src.ch01.practice.p1_pig_latin.
encode
(word: str) → str[source]¶ Check if word starts with vowel, then translate to Pig Latin.
If a word begins with a consonant, move the consonant to the end of the word and add ‘ay’ to the end of the new word. If a word begins with a vowel in
VOWELS
, add ‘way’ to the end of the word.
src.ch01.practice.p2_poor_bar_chart module¶
Takes a sentence as input and returns a ‘bar chart’ of each letter.
-
src.ch01.practice.p2_poor_bar_chart.
freq_analysis
(sentence: str) → dict[source]¶ Perform frequency analysis of letters in sentence.
Iterate through each letter in the sentence and add it to a dictionary of lists using
collections.defaultdict
.- Parameters
sentence (str) – String to count letters of.
- Returns
defaultdict
with each letter as keys and alist
with letters repeated based on their frequency as values.
Example
>>> from src.ch01.practice.p2_poor_bar_chart import freq_analysis >>> test = 'aaabbbccc' >>> freq_analysis(test) defaultdict(<class 'list'>, {'a': ['a', 'a', 'a'], 'b': ['b', 'b', 'b'], 'c': ['c', 'c', 'c']})
- Raises
TypeError – If sentence is not a string.
-
src.ch01.practice.p2_poor_bar_chart.
print_bar_chart
(freq_dict: dict) → None[source]¶ Print dictionary to terminal.
Use
pprint.pprint()
to print dictionary with letter frequency analysis to terminal.- Parameters
freq_dict (dict) – Dictionary with frequency analysis from
freq_analysis()
.- Returns
None
. Prints freq_dict.- Raises
TypeError – If freq_dict is not a dictionary.
Module contents¶
Chapter 1 Practice Projects.
-
src.ch01.practice.
VOWELS
¶ Tuple containing characters of the English vowels (except for ‘y’)
- Type
-
src.ch01.practice.
FREQ_ANALYSIS_ERROR
¶ String with
TypeError
for Poor Bar Chartfreq_analysis()
.- Type
-
src.ch01.practice.
PRINT_BAR_CHART_ERROR
¶ String with
TypeError
for Poor Bar Chartprint_bar_chart()
.- Type