Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.1K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Lists of Key Values Derived from Key-Value Pairs Using Associations

Posted 12 years ago
POSTED BY: Jon Rogers

The second argument of Position is a pattern to look for

?Position

Position[expr,pattern] gives a list of the positions at which objects matching pattern appear in expr. 
Position[expr,pattern,levelspec] finds only objects that appear on levels specified by levelspec. 
Position[expr,pattern,levelspec,n] gives the positions of the first n objects found. 
Position[pattern] represents an operator form of Position that can be applied to an expression. >>

In your Association the pattern {16505, 91521} does not appear

Note I left out the quotation marks that you had in it since the association you give as an example has lists of integers on the right hand side:

In[1]:=  temp = <| 234 -> {16504, 16505},  456 -> {91521} |>

To get what I think you are after you need to put Alternatives in the second argument of Position, not a list of values, as in

In[2]:= Position[temp, 16504 | 91521]


Out[2]= {{Key[234], 1}, {Key[456], 1}}
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard