Re: keys in a hash table (aka, all assigned indices in an array): awf
- To: mathgroup at smc.vnet.net
- Subject: [mg13370] Re: [mg13281] keys in a hash table (aka, all assigned indices in an array): awf
- From: BobHanlon at aol.com
- Date: Mon, 20 Jul 1998 02:50:22 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Daniel, An equivalent approach: fruits[apple] = crunchy; fruits[lemon] = sour; keys[hash_Symbol] := #[[1, 1, 1]]& /@ DownValues[hash]; keys[fruits] {apple,lemon} fruits/@keys[fruits] {crunchy,sour} Bob Hanlon In a message dated 7/17/98 9:18:42 AM, dreeves at flip.eecs.umich.edu wrote: >suppose I make some assignments like this: > fruits[apple]= crunchy > fruits[lemon]= sour > >I'm treating fruits like a hash table and now I would like a list of all >the keys. In this case {apple,lemon}. > >It seems like there should be an easy way to do this. All I came up with >was the following hack: > >keys[hash_]:= > DownValues[hash] /. {RuleDelayed->(#&), hash->(#&)} //ReleaseHold > > >the hash values will be simple; we can just do fruits/@keys[fruits]