Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
m Mathematica and Wolfram Language: <source lang="mathematica">
Line 658:
 
Mathematica uses the Association<ref>https://reference.wolfram.com/language/ref/Association.html</ref> expression to represent associative arrays.
<source lang="mathematica">
 
phonebook = <| "Sally Smart" -> "555-9999",
"John Doe" -> "555-1212",
"J. Random Hacker" -> "553-1337" |>;
</source>
 
To access<ref>https://reference.wolfram.com/language/ref/Key.html</ref>
<source lang="mathematica">
 
phonebook[[Key["Sally Smart"]]]
</source>
 
If the keys are strings, the ''Key'' keyword is not necessary, so:
<source lang="mathematica">
 
phonebook<nowiki>[["Sally Smart"]]
</nowikisource>
 
To list keys<ref>https://reference.wolfram.com/language/ref/Keys.html</ref> and values<ref>https://reference.wolfram.com/language/ref/Values.html</ref>