def zara (L): '' 'list of str-> int Precondition: len (L)> 0 Returns the number of words that constitute pairs of consecutive words of the same length. For example: in the list ["a", "yes", "case", "of", "not", "aha", "then", "very", "n", "tables"] the answer is 6 because the words of consecutive pairs of the same length "yes", "case", "not", "aha", "then", "very" are counted. For simplicity, you can assume that every 2 consecutive words of the same length are followed a word (or pairs of words) of different length (there are no 3 consecutive words of the same length), such as in the test examples below: >>> zara (["from", "very", "good", "big"]) 2 >>> zara (["or", "is", "like", "this"]) 0 >>> zara (["lions", "not", "case", "oh", "yes", "aha", "z"]) 4 >>> zara (["a", "yes", "case", "of", "not", "aha", "then", "very", "n", "tables"]) 6
def zara (L):
'' 'list of str-> int
Precondition: len (L)> 0
Returns the number of words that constitute pairs of consecutive words of the same length.
For example: in the list ["a", "yes", "case", "of", "not", "aha", "then", "very", "n", "tables"] the answer is 6 because
the words of consecutive pairs of the same length "yes", "case", "not", "aha", "then", "very" are counted.
For simplicity, you can assume that every 2 consecutive words of the same length are followed
a word (or pairs of words) of different length (there are no 3 consecutive words of the same length), such as
in the test examples below:
>>> zara (["from", "very", "good", "big"])
2
>>> zara (["or", "is", "like", "this"])
0
>>> zara (["lions", "not", "case", "oh", "yes", "aha", "z"])
4
>>> zara (["a", "yes", "case", "of", "not", "aha", "then", "very", "n", "tables"])
6
'' '
Step by step
Solved in 2 steps