1
$\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.

| improve this question | | | | |
$\endgroup$
5
$\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}}

| improve this answer | | | | |
$\endgroup$

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