spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Checking for syllables, python


Here's how the question breaks down:

(1) the signature of the required function:

r""" (list of str, poetry pattern,
pronunciation dictionary) -> list of str

(2) a guarantee about the structure of the inputs:

Precondition: len(poem_lines) ==
len(pattern[0])

(3) specification of the returm value:

Return a list of lines from poem_lines
that do not have the right number of
syllables for the poetry pattern according to the
pronunciation dictionary.
If all lines have the right number of syllables,
return the empty list.

(4) sample input - first argument [list of str]:

>>> poem_lines = ['The first
line leads off,', 'With a gap before the next.',
'Then the poem ends.']

(5) sample input - second argument [poetry pattern]:

>>> pattern = ([5, 5, 4],
['*', '*', '*'])

(6) sample input - third argument [pronunciation dictionary]:

>>> word_to_phonemes =
{'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
...                     'GAP': ['G', 'AE1', 'P'],
...                     'BEFORE': ['B', 'IH0',
'F', 'AO1', 'R'],
...                     'LEADS': ['L', 'IY1', 'D',
'Z'],
...                     'WITH': ['W', 'IH1',
'DH'],
...                     'LINE': ['L', 'AY1', 'N'],
...                     'THEN': ['DH', 'EH1',
'N'],
...                     'THE': ['DH', 'AH0'], 
...                     'A': ['AH0'], 
...                     'FIRST': ['F', 'ER1', 'S',
'T'], 
...                     'ENDS': ['EH1', 'N', 'D',
'Z'],
...                     'POEM': ['P', 'OW1',
'AH0', 'M'],
...                     'OFF': ['AO1', 'F']}

(7) first sample output - return value [list of str]:

>>>
check_syllables(poem_lines, pattern,
word_to_phonemes)
['With a gap before the next.', 'Then the poem
ends.']

(8) second sample output - return value [list of str]:

>>> poem_lines = ['The first
line leads off,']
>>> check_syllables(poem_lines, ([0],
['*']), word_to_phonemes)
[]
"""

The first sample output (7) shows the expected return value for input lines (5) which do not match the pattern (6). That is, the three input lines have the pattern [5, 7, 5], which does not match the pattern [5, 5, 4] in the last two elements, and so the corresponding lines are returned by the function.

The second sample input (8) shows what the output should be when the input lines (5) do match the pattern (6) - i.e. an empty list should be returned.

PS:

It looks like there is a in error in (8). The sample code should probably be:

>>>
check_syllables(poem_lines, ([5], ['*']),
word_to_phonemes)

Categories : Python

Related to : Checking for syllables, python
Counting Syllables In String
If I understand correctly what are you asking you want to transform line like this 'The first line leads off' to list like this: [ ['DH', 'AH0'], # The ['F', 'ER1', 'S', 'T'], # first ['L', 'AY1', 'N'], # line ['L', 'IY1', 'D', 'Z'], # leads ['AO1', 'F'] # off ] And count number of elements that contain number (5 in provided example - AH0, ER1, AY1,

Categories : Python
Python - Merging 2 lists of tuples by checking their values
Convert a and b to dictionaries first using the first(use str.lower() in it) and third item as key and then later on loop on the union of the keys in a list comprehension to get the desired output: >>> from pprint import pprint >>> dct_a = {(x[0].lower(), x[2]): x for x in a} >>> dct_b = {(x[0].lower(), x[2]): x for x in b} >>> out = [(dct_a.get(k), dct_b.get(k

Categories : Python
Checking for near-same IPs
Don't store IP addresses as strings if you want to run queries on them later. Convert them to a proper numeric address using ip2long ip2long — Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address For example echo ip2long("123.123.123.123"); //2071690107 echo " "; echo ip2long("123.123.123.124"); //2071690108 Notice the pattern (1+)? Now yo

Categories : PHP
Checking for int in int array
Arrays.asList(thirtyOneDays) returns a List containing a single entry of type int[] which is different from any of the integers in the original List.

Categories : Java
checking to see if data attribute has a value or not
You could use this. if (!$('#myImg').data('tablet')) { alert('Path not Set'); }; In Javascript every object is convertible to a boolean, so if it's null or an empty string it'll be false, otherwise it'll be true.

Categories : Javascript
Recently Add
Overriding save method vs Model Method?
function encrypt file - input & output to same file in python
urllib.error.URLError:
python if statement fails to compute compound logic
referencing sphinx generated Python docs from YAML file
Subclassing datetime64
filter view from url parameter with an intermediate model?
How to stream twitter mentions with tweepy?
How to space out rows and columns in Python Tkinter
Python: Using BeautifulSoup to save content to CSV
Python - Take parts of a txt file and put them in another txt
Python socket send doesn't send the whole string
Python: prime test
How to import one day old logs
Appending filters to django models
Python: parsing .xls file failed with both xlrd and pandas
writing pandas dataframe columns to csv rows staggered
parse_args doesn't seem to understand json arguments
Django ORM, get data
Pygame, keep jumping and glitching through the "ground"
Is it possible to import a class defined inside a function?
How to handle a variable number of nested for loops?
Boolean expression with strings
Object duplicated when using processing.Manager?
What is the syntax of PBS job limit directive
python 3.x overwrite previous terminal line
Deploying django app. on heroku (gunicorn, wsgi issue)
How can I create an "ID" column in one dataframe based on the index of another dataframe?
PIL Module Error
pandas.read_html returns only one table
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.