0
$\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$
2
$\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$
  • $\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 '14 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 '14 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 '14 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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