Mathematica Help with Mathematica? Find Dictionary Lengths & Longest Words

  • Thread starter Thread starter fruitbygrace
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

This discussion focuses on optimizing Mathematica code for retrieving dictionary data, specifically the number of words in various languages and the lengths of the longest words. The user initially attempts to create lists using DictionaryLookup and Length, but seeks a more efficient approach. The recommended solution involves utilizing the Map function to apply operations across lists, which simplifies the process of generating the desired outputs.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of the DictionaryLookup function in Mathematica
  • Knowledge of list manipulation functions such as Length and Max
  • Basic understanding of functional programming concepts, particularly the Map function
NEXT STEPS
  • Learn how to effectively use the Map function in Mathematica
  • Explore the DictionaryLookup function to understand its parameters and outputs
  • Investigate string manipulation functions like StringLength in Mathematica
  • Study error diagnosis techniques in Mathematica to troubleshoot code issues
USEFUL FOR

Mathematica users, programmers seeking to optimize dictionary data retrieval, and anyone interested in functional programming techniques within the Mathematica environment.

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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K