1
$\begingroup$

I have a lookup table with about 30 rows. Column 1 has the value I want to search for and column 2 has the value I want returned. It seemed like I should be able to use rules to do this, but clearly I don't know what I'm doing. Oh, the values are all strings

I tried:

rule2 :> (#[[1]] -> #[[2]]) & /@ elrALobMap;

This didn't work. First, should I be doing this a different way? (I see that I can do it with Position and Pick, but that seemed awkward. Second, I'd appreciate any help in understanding how (if it's possible) what I did code should be coded.

$\endgroup$
  • $\begingroup$ Please provide a few short sample lines of your table. $\endgroup$ – Yves Klett Oct 31 '13 at 16:00
3
$\begingroup$
elrALobMap = Transpose@{ToString /@ Range@30, ToString /@ Reverse@Range@30}
rules = Dispatch[RuleDelayed @@@ elrALobMap]
"1" /. rules
(*
30
*)
$\endgroup$
  • $\begingroup$ Works great! Thanks. $\endgroup$ – Mitchell Kaplan Oct 31 '13 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.