3
$\begingroup$

I have a deep nested ragged list.

list= {{{
        {{0}, 13}, {{1}, 15}, {{0, 0}, 12}, {{1, 1}, 9}, … , 
        {{0}, 3}, {{1}, 5}, {{0, 0}, 2}, {{1, 1}, 19}, … 
       }}}

The list is the result of obtaining a Tally around a string of 0s and 1s that has been Split to identify runs.

I am interested in finding all of the occurrences of say {0, 0} from the nested list. I tried Position

Position[list, {0, 0}]

It works fine and I get:

{{1, 1, 3, 1}, {1, 2, 3, 1}, {1, 3, 2, 1}, …

However, I wanted to use Select or Cases to pull out the elements that contained the element of interest. I've tried to follow some examples at https://stackoverflow.com/questions/7893090/selectnested-list-condition-in-mathematica.

For example, I tried:

   Select[list, #[[_, _, _, y_]] == {0, 0} &]
   Cases[list, {_, _, _, y_} /; y == {0, 0}]

However, I was unsuccessful. I suspect that I am not defining the depth for the search as a proper list.

$\endgroup$

closed as off-topic by m_goldberg, Dr. belisarius, MarcoB, WReach, user9660 Feb 24 '16 at 5:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, Dr. belisarius, MarcoB, WReach, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Cases[list, {0, 0}, Infinity]? $\endgroup$ – garej Feb 23 '16 at 21:01
  • 1
    $\begingroup$ @Muralli, you may also want to see Extract, as Extract[list, Position[list, {0, 0}]] $\endgroup$ – garej Feb 23 '16 at 21:04
  • $\begingroup$ Murally, please include a more representative example of your list. If too big, use pastebin or a similar service to post the whole list. Also, when you say that you want to extract the elements that contain {0, 0}, do you mean the immediately enclosing list? $\endgroup$ – MarcoB Feb 23 '16 at 21:20
  • 1
    $\begingroup$ Cases[list, {{0, 0}, _}, ∞] $\endgroup$ – m_goldberg Feb 23 '16 at 22:21
  • $\begingroup$ @m_goldberg: {0,0} is an example of the pattern I am searching for in the ragged nested list. It is a vector list itself. I am going to see if I post the list on pastern. Will let you know when I do. $\endgroup$ – Murali Feb 23 '16 at 22:34