4
$\begingroup$

I have the following list

l = {{123, "style", "", "url", "TRUE", "TRUE", "TRUE"},
     {456, "style", "", "url", "TRUE", "True", "TRUE"},
     {789, "style", "", "url", "FALSE", "FALSE", "TRUE"},
     {112, "style", "", "url", "TRUE", "TRUE", "TRUE"},
     {223, "style", "", "url", "FALSE", "FALSE", "TRUE"}};

How can I select the ones that their 5th element is "FALSE" namely the output should look like:

{{789, "style", "", "url", "FALSE", "FALSE", "TRUE"},
 {223, "style", "", "url", "FALSE", "FALSE", "TRUE"}}
$\endgroup$
6
$\begingroup$

There are lots of different ways. The most common ones would be:

Cases[l, {_, _, _, _, "FALSE", _, _}]

{{789, "style", "", "url", "FALSE", "FALSE", "TRUE"}, {223, "style", "", "url", "FALSE", "FALSE", "TRUE"}}

Select[l, #[[5]] == "FALSE" &]

{{789, "style", "", "url", "FALSE", "FALSE", "TRUE"}, {223, "style", "", "url", "FALSE", "FALSE", "TRUE"}}

| improve this answer | |
$\endgroup$
3
$\begingroup$
l//Pick[#, #[[All,5]], "FALSE"]&

{{789, style, , url, FALSE, FALSE, TRUE}, {223, style, , url, FALSE, FALSE, TRUE}}

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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