Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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]] &]
share|improve this answer
    
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. –  user720329 Apr 19 at 22:10
    
This can take some time to run because DictionaryLookup downloads some data. Added function for longestwords which I missed first time responding –  pjc42 Apr 20 at 0:02
    
This takes less than a minute on my machine, and as little as 10 seconds once the dictionaries are downloaded. –  pjc42 Apr 20 at 0:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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