Re: Data set association, returning values
- To: mathgroup at smc.vnet.net
- Subject: [mg131723] Re: Data set association, returning values
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 24 Sep 2013 04:15:34 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20130924015750.0A2ED6A28@smc.vnet.net>
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 at 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? > >
- References:
- Data set association, returning values
- From: Float <float71@gmail.com>
- Data set association, returning values