0
$\begingroup$

Good morning,

I have a list with each element containing a tuple and a single. It is of this form:

{{{{2015,5,13},{2015,8,31}},100}, {{{2010,2,3},{2010,2,17}},14},......}

I am trying to select elements that have the last element equal to 100. I want the output to be the entire element, so in this example I want {{{2015,5,13},{2015,8,21}},100} to be output.

My list is called dbp, and the select function I have been trying is:

Select[dbp, dbp[[#]][[2]] == 100 & /@ Range[Length[dbp]]]

This always returns an empty set.

I know my calling of that element is correct, because:

dbp[[12]][[2]]

displays the proper element. I also know that the element is findable because:

(dbp[[#]][[2]] == 100) & /@ Range[Length[dbp]]

yields True for the element I am looking for. What I can't figure out is why this doesn't work in the Select function. Any help would be much appreciated.

$\endgroup$

closed as off-topic by Bob Hanlon, m_goldberg, MarcoB, Öskå, Michael E2 Aug 23 '15 at 23:44

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." – Bob Hanlon, m_goldberg, MarcoB, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

4
$\begingroup$

You are using a wrong syntax for Select

data = {{{{2015, 5, 13}, {2015, 8, 31}}, 100}, {{{2010, 2, 3}, {2010, 2, 17}},
     14}, {{{2013, 5, 13}, {2013, 8, 31}}, 
    100}, {{{2010, 2, 3}, {2010, 2, 17}}, 
    14}, {{{2011, 5, 13}, {2011, 8, 31}}, 
    100}, {{{2010, 2, 3}, {2010, 2, 17}}, 14}};

Select[data, #[[-1]] == 100 &]

{{{{2015, 5, 13}, {2015, 8, 31}}, 100}, {{{2013, 5, 13}, {2013, 8, 31}}, 100}, {{{2011, 5, 13}, {2011, 8, 31}}, 100}}

Select[data, #[[2]] == 100 &]

{{{{2015, 5, 13}, {2015, 8, 31}}, 100}, {{{2013, 5, 13}, {2013, 8, 31}}, 100}, {{{2011, 5, 13}, {2011, 8, 31}}, 100}}

$\endgroup$

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