MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: dictionaries?

Joe Strout wrote:
> In Python, there's an extremely handy datatype called a "dictionary"
> which implements a many-to-1 mapping between keys (which can be any
> hashable type) and values (which can be anything).  E.g.:
> > d = {"one":1, "two":2}
> > d["one"]
> 1
> > d["three"]
> (key not found)
> I'm looking for something similar in Mathematica -- it's a great way to
> organize lists of parameters, without having to worry about the order
> in which they are listed.
> I've searched the online help and flipped through the Mathematica book,
> but I can't find anything like this.  Have I missed something?
> Thanks,
> -- Joe
> --
> ,------------------------------------------------------------------.
> |    Joseph J. Strout           Biocomputing -- The Salk Institute |
> |    joe at                 |
> `------------------------------------------------------------------'
> Check out the Mac Web Directory!

You could just say


or if you have a list like this 

you could do like this


If you want the function to alert you when there is no key found, you
could, in both cases, add:

	d::nokey="Key not found"

Hope that helps


  • Prev by Date: Re: Basic Laplace Transforms
  • Next by Date: Re: Separating
  • Previous by thread: Re: dictionaries?
  • Next by thread: Re: Re: dictionaries?