id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com > natalie
prev  |  next  |  chance

A Portmanteau Word is a blend of two or more words, like 'mathelete', which comes from 'math' and 'athelete'. You will write the function natalie(words), which finds the best portmanteau that can be made by combining any two of the given words. Of course "best" is subjective, and you are welcome to make up your own judging rules, but in this exercise the rules are: a portmanteau must be composed of three non-empty pieces, start+mid+end, where both start+mid and mid+end are given words. For example, 'adolescented' comes from 'adolescent' and 'scented', with start+mid+end='adole'+'scent'+'ed'. That defines an allowable combination, but which is best? Intuitively, a longer word is better, and a word is well-balanced if the mid is about half the total length while start and end are 1/4 each. To make that specific, the score for a word w is the number of letters in w minus the difference between the actual and ideal lengths of start, mid, and end. (For the example w='adole'+'scent'+'ed': the start/mid/end/whole lengths are 5/5/2/12, yielding a score of 12 - abs(5-(12/4)) - abs(5-(12/2)) - abs(2-(12/4)) = 8. The output of natalie(words) should be the best portmanteau, or None if there is none. Note (1): I got the idea for this exercise from Darius Bacon at http://wry.me/blog/ . Note (2): In real life, many portmanteaus omit letters, for example 'smoke' + 'fog' = 'smog'; we aren't considering those. Note (3): The word 'portmanteau' is itself a portmanteau; it comes from the French "porter" (to carry) + "manteau" (cloak), and in English meant "suitcase" in 1871 when Lewis Carroll used it in 'Through the Looking Glass' to mean two words packed into one.


natalie(['eskimo', 'escort', 'kimchee', 'kimono', 'cheese']) → 'eskimono'
natalie(['kimono', 'kimchee', 'cheese', 'serious', 'us', 'usage']) → 'kimcheese'
natalie(['circus', 'elephant', 'lion', 'opera', 'phantom']) → 'elephantom'

...Save, Compile, Run (ctrl-enter)

def natalie(words):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 497 Post-solution available

Copyright Nick Parlante 2017 - privacy