Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #15528
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Data set association, returning values |
| Date | 2013-09-24 08:14 +0000 |
| Message-ID | <l1rhlo$q6f$1@smc.vnet.net> (permalink) |
| References | <20130924015750.0A2ED6A28@smc.vnet.net> |
| Organization | Time-Warner Telecom |
objects = "Object" <> # & /@
CharacterRange["A", "T"]
values = "Page" <> ToString[#] & /@
ReplacePart[
RandomInteger[{1, 100}, Length[objects]],
3 -> 67]
Some alternative approaches
Clear[value1, value2, value3];
value1[obj_?(MemberQ[objects, #] &)] :=
value1[obj] =
values[[Position[objects, obj][[1]]]][[1]];
value2[obj_?(MemberQ[objects, #] &)] :=
value2[obj] =
Cases[Thread[{objects, values}],
{obj, val_} :> val][[1]];
(value3[#[[1]]] = #[[2]]) & /@
Thread[{objects, values}];
#["ObjectC"] & /@
{value1, value2, value3}
{"Page67", "Page67", "Page67"}
Equal @@ %
True
Neither value1, value2, nor value3 will evaluate for arguments not in
objects list
#["ObjectZ"] & /@
{value1, value2, value3}
{value1["ObjectZ"], value2["ObjectZ"], value3["ObjectZ"]}
value1, value2, and value3 are equivalent
value1 /@ objects ==
value2 /@ objects ==
value3 /@ objects ==
values
True
Bob Hanlon
On Mon, Sep 23, 2013 at 9:57 PM, Float <float71@gmail.com> wrote:
> Hello all,
> I am a complete newbie to Mathematica, and I want to do the following:
>
> -Associate a data set of 20 objects to certain values.
> -Call the object and return its associated value.
>
> For example, I want to input "ObjectC" and have returned "Page67".
>
> How do I achieve this?
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Data set association, returning values Bob Hanlon <hanlonr357@gmail.com> - 2013-09-24 08:14 +0000
csiph-web