4
$\begingroup$

I have the following list:

l={"apple","orange","kiwi","APPLE","lemon"}

How can I make a command so the capitalised word would be returned? So in this case the output should be

{"APPLE"}

Surely one can do l[[4]] but this is not what I am looking for, I want to have a command to search on a long list and return the capital words. Also note that in my case the whole word is in capital letter not only the first letter. Also assume that I don't know what would be the capital word, I just know that I have a list and somewhere in it there is a capitalised letter word, I need to find those.

$\endgroup$
7
$\begingroup$
l = {"apple", "orange", "kiwi", "APPLE", "lemon", "Lemon", "leMon"};
Select[l, UpperCaseQ]

{"APPLE"}

$\endgroup$
  • $\begingroup$ Ah, I need to recalibrate my gedanken Mathematica; I didn't know that plain UpperCaseQ[] will still work! :) $\endgroup$ – J. M. is away Oct 12 '18 at 11:55
  • $\begingroup$ @J.M. my gedanken mma would have tried #==ToUpperCase[#]&:) $\endgroup$ – kglr Oct 12 '18 at 12:00
2
$\begingroup$

Try

Select[l, StringMatchQ[__?UpperCaseQ]]
$\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.