Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is python programming question. Please follow the restrictions. This is python programming question. Please follow the restrictions. This is python programming question. Please follow

This is python programming question. Please follow the restrictions.

This is python programming question. Please follow the restrictions.

This is python programming question. Please follow the restrictions.

image text in transcribed

image text in transcribed

nat Tools Add-ons Help Last edit was seconds ago ormal text Arial 11.5 + BIU A 1 III 2 1 1 2 3 4 5 6. 7 8 9 10 11 12 13 14 1 151 17 18 RESTRICTIONS Only allowed: variables, if statements, while loops. Functions: len(), int(), float(), type (), isinstance (), abs (). String methods: format(), isalpha (), lower(), upper (). List operators and methods: create [ ], list(), append(). Keywords: elif, else, return, break, continue, def, self, None, try, raise, except, finally, is, import sys. Any exception handling. Remember: Do NOT use for loops or the in keyword. Do NOT use min () /max(), enumerate ()/zip() or sorted(). Do NOT use negative indexing (e.g. ls(-1]) or slicing (e.g. (1:1). Do NOT use any other list operations or string methods. Marks will be deducted. A consonant digraph is a sound represented by a pair of (exactly two) consonants, such as sh, gr and bl in the English language. Write a function find_shortest() that takes as input a list and a consonant digraph, and outputs the shortest string in the list containing the digraph. To simplify matters, for the purposes of this question, you may assume that all letters in the English alphabet except a, e, i, o and u are consonants, and that any non-repeated pairing of the consonants is a valid digraph. You may also assume that the input list is always a list of strings containing only lowercase letters of the English alphabet a to z. If the input digraph is not a string, raise a TypeError with the message Unexpected input data type. If the input string is not a valid digraph, raise a valueError with the message Invalid digraph. . If more than one string of the same longest length exists, return the first one. If no such string exists, return an empty string '. Examples: find_shortest(['church', 'c', 'etch'], 'ch') # 'etch' find_shortest(['hash', 'bash'], 'sh') # 'hash find_shortest(['trail', 'garage'], 'gr') find_shortest([], 'br') find_shortest(['shell', 'ash'], 12) # TypeError find_shortest(['trampoline', 'actor'], 't') # ValueError find_shortest(['lasso', 'less'], 'ss') # ValueError find_shortest(['bismuth'], 'bi') # ValueError find_shortest(['shrill', 'ash'], 'shr') # ValueError

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions