1
$\begingroup$

a. Make a function longest[lang_] that gives the length of the longest word in the dictionary of lang. You should get longest["French"]=25

For this part, I have lang = DictionaryLookup[All];
longest[lang_] := Max[StringLength[lang]]

But this isn't working.

b. Now give a list with entries {language,longest[language]}. Table[{lang[[i]], Length[DictionaryLookup[{lang[[i]], All}]]}, {i, 1, Length[lang]}] Again not working

c. Make a function lonegestwords[lang_] that gives the output {longest[lang],lang,longwords} where longwords is the list of the words of longest length in lang.

I tried longestwords[lang_] := {longest[lang], lang, Select[DictionaryLookup[{lang, All}], StringLength[#] == longest[lang] &]}

d. Now get the list with entries longestwords[lang] for all languages and sort it in descending order by the longest word. I know that I have to use Sort[longestwords[lang],#2[[1]]<#1[[1]]&] But since I don't have the function, I can't do it.

$\endgroup$

1 Answer 1

3
$\begingroup$

You might try the following

languages = DictionaryLookup[All]

longest[lang_] := longest[lang] = Max[StringLength[DictionaryLookup[{lang, All}]]]

SortBy[Table[{lang, longest[lang]}, {lang, languages}], Last]

longestwords[lang_] := longestwords[lang] =
   {
     lang, longest[lang], 
     Select[DictionaryLookup[{lang, All}],(StringLength[#] == longest[lang]) &]
   }

SortBy[longestwords /@ languages, #[[2]] &]
$\endgroup$
3
  • $\begingroup$ Thanks for your help, but do you know how to do part d? What I did is longestwords[lang_] := {longest[lang], lang, Select[DictionaryLookup[{lang, All}],StringLength[#] == longest[lang] &]} and then longestwords[All] but it is taking a long time to give me the answer. $\endgroup$
    – user720329
    Apr 19, 2014 at 22:10
  • $\begingroup$ This can take some time to run because DictionaryLookup downloads some data. Added function for longestwords which I missed first time responding $\endgroup$
    – pjc42
    Apr 20, 2014 at 0:02
  • $\begingroup$ This takes less than a minute on my machine, and as little as 10 seconds once the dictionaries are downloaded. $\endgroup$
    – pjc42
    Apr 20, 2014 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.