Help with Mathematica? Find Dictionary Lengths & Longest Words

  • Context: Mathematica 
  • Thread starter Thread starter fruitbygrace
  • Start date Start date
  • Tags Tags
    Mathematica
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
fruitbygrace
Messages
1
Reaction score
0
Part A:
Get the list of pairs of the form {language,number of words in dictionary}. Call this list Alength.

What I did:
lang = DictionaryLookup[All] to get all the languages. Then,
Alength = {Length[DictionaryLookup[{"Finnish", All}]], Length[DictionaryLookup[{"Arabic", All}]]}...}

What is a shorter way of doing this?


-------------
Part B:

Get a list of the form {language, length longest word in the dictionary}. Call this list longestword.

I did:
longestword = Max[DictionaryLookup[All]]

But that's not coming out correctly.


--------------
Part C:
Look at all the words contained in all the dictionaries. What are the ones of maximum length?

I did:
Max[StringLength[lang]]

It comes out as 19, but I think there's something wrong here as well.


--------------
Part D:
What are all the words of length 20 in the Mathematica English dictionary.
This one I have no idea.
 
Physics news on Phys.org
fruitbygrace said:
Part A:
Get the list of pairs of the form {language,number of words in dictionary}. Call this list Alength.

What I did:
lang = DictionaryLookup[All] to get all the languages. Then,
Alength = {Length[DictionaryLookup[{"Finnish", All}]], Length[DictionaryLookup[{"Arabic", All}]]}...}

What is a shorter way of doing this?

Almost every time you "want to do the same thing to every element in a list" the solution is to use the Map function. Look in the help system for Map and see if you can see a way to use that.

There are two methods of using this, first to define a function like f and then use Map[f, lang], the second is to use a shortcut method of defining functions using # and &. That second method is probably difficult to understand initially, so using the first method might be best to start with.

fruitbygrace said:
Part B:

Get a list of the form {language, length longest word in the dictionary}. Call this list longestword.

I did:
longestword = Max[DictionaryLookup[All]]

But that's not coming out correctly.

Hint: What is DictionaryLookup[All] and what would Max of that be? Why would that not be what you want? It is also possible that you might have mis-quoted that question.


fruitbygrace said:
Part C:
Look at all the words contained in all the dictionaries. What are the ones of maximum length?

I did:
Max[StringLength[lang]]

It comes out as 19, but I think there's something wrong here as well.

Again, look at StringLength[lang] and see if that is exactly what Max will accept.

fruitbygrace said:
Part D:
What are all the words of length 20 in the Mathematica English dictionary.
This one I have no idea.

Study the hints. Try to understand the method they are suggesting for diagnosing when something doesn't work. Then see if you can apply those ideas to make progress on the last problem.