Find non-case sensitive string in a mixed list of elements? The Next CEO of Stack...
Is there a difference between "Fahrstuhl" and "Aufzug"
Is there a way to save my career from absolute disaster?
Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?
Method for adding error messages to a dictionary given a key
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
Domestic-to-international connection at Orlando (MCO)
Flying from Cape Town to England and return to another province
How to install OpenCV on Raspbian Stretch?
How many extra stops do monopods offer for tele photographs?
Are police here, aren't itthey?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Why do remote US companies require working in the US?
Axiom Schema vs Axiom
Why didn't Khan get resurrected in the Genesis Explosion?
Math-accent symbol over parentheses enclosing accented symbol (amsmath)
Do I need to write [sic] when a number is less than 10 but isn't written out?
Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?
Where do students learn to solve polynomial equations these days?
Solving system of ODEs with extra parameter
A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Need help understanding a power circuit (caps and diodes)
What flight has the highest ratio of time difference to flight time?
Find non-case sensitive string in a mixed list of elements?
Find non-case sensitive string in a mixed list of elements?
The Next CEO of Stack OverflowBuilding a list recursive with one or more argumentsReturn Functions from parallel execution of moduleFast method to select matrix elements based on a vector of positionsIssue with very large lists in MathematicaFaster position list construction from a “take instructions” listConvert elements of list to stringAdding a collection of neighbors to points in a list, concatenating strings, parallelization/optimizing run-time?Get sublists by pattern?Obtaining the position in a list where the i^th element is bigger than the (i+1)^th elementExtract all instances of variables matching a pattern?
$begingroup$
Consider an example list with mixed element types, e.g.:
list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" };
I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:
findPosition[list,"abc"]
{{3,1}}
Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?
EDIT:
My current workaround is:
findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]
list-manipulation function-construction searching
$endgroup$
add a comment |
$begingroup$
Consider an example list with mixed element types, e.g.:
list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" };
I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:
findPosition[list,"abc"]
{{3,1}}
Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?
EDIT:
My current workaround is:
findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]
list-manipulation function-construction searching
$endgroup$
add a comment |
$begingroup$
Consider an example list with mixed element types, e.g.:
list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" };
I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:
findPosition[list,"abc"]
{{3,1}}
Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?
EDIT:
My current workaround is:
findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]
list-manipulation function-construction searching
$endgroup$
Consider an example list with mixed element types, e.g.:
list = { 1.234 , a[2] , {"Abc" , 4/5} , "acb" };
I would like to have a function that finds the position of a string, without regard to upper or lower characters, e.g.:
findPosition[list,"abc"]
{{3,1}}
Is there a function like that in Mathematica? Or maybe one can implement it with efficient performance?
EDIT:
My current workaround is:
findPosition[list_,str_]:=Position[list/.x_String:>ToLowerCase[x],ToLowerCase[str]]
list-manipulation function-construction searching
list-manipulation function-construction searching
edited 2 hours ago
Kagaratsch
asked 2 hours ago
KagaratschKagaratsch
4,77631348
4,77631348
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Position[list, s_String /; ToLowerCase[s] == "abc"]
{{3, 1}}
or
Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]
$endgroup$
$begingroup$
I like how this does not need to make substitutions inlist
itself to search it!
$endgroup$
– Kagaratsch
2 hours ago
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.
$endgroup$
– C. E.
1 hour ago
add a comment |
$begingroup$
Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:
list = {1.234, a[2], {"Abc", 4/5}, "acb"};
ToLowerCase[list]
(* Out: {ToLowerCase[1.234], ToLowerCase[a[2]], {"abc", ToLowerCase[4/5]}, "acb"} *)
That should not bother you though; it certainly does not bother Position
:
Position[ToLowerCase[list], "abc"]
(* Out: {{3, 1}} *)
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194280%2ffind-non-case-sensitive-string-in-a-mixed-list-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Position[list, s_String /; ToLowerCase[s] == "abc"]
{{3, 1}}
or
Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]
$endgroup$
$begingroup$
I like how this does not need to make substitutions inlist
itself to search it!
$endgroup$
– Kagaratsch
2 hours ago
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.
$endgroup$
– C. E.
1 hour ago
add a comment |
$begingroup$
Position[list, s_String /; ToLowerCase[s] == "abc"]
{{3, 1}}
or
Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]
$endgroup$
$begingroup$
I like how this does not need to make substitutions inlist
itself to search it!
$endgroup$
– Kagaratsch
2 hours ago
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.
$endgroup$
– C. E.
1 hour ago
add a comment |
$begingroup$
Position[list, s_String /; ToLowerCase[s] == "abc"]
{{3, 1}}
or
Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]
$endgroup$
Position[list, s_String /; ToLowerCase[s] == "abc"]
{{3, 1}}
or
Position[list, s_String?(EqualTo["abc"]@*ToLowerCase)]
answered 2 hours ago
Henrik SchumacherHenrik Schumacher
58.6k581162
58.6k581162
$begingroup$
I like how this does not need to make substitutions inlist
itself to search it!
$endgroup$
– Kagaratsch
2 hours ago
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.
$endgroup$
– C. E.
1 hour ago
add a comment |
$begingroup$
I like how this does not need to make substitutions inlist
itself to search it!
$endgroup$
– Kagaratsch
2 hours ago
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.
$endgroup$
– C. E.
1 hour ago
$begingroup$
I like how this does not need to make substitutions in
list
itself to search it!$endgroup$
– Kagaratsch
2 hours ago
$begingroup$
I like how this does not need to make substitutions in
list
itself to search it!$endgroup$
– Kagaratsch
2 hours ago
1
1
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.$endgroup$
– C. E.
1 hour ago
$begingroup$
Position[ToLowerCase[list], "abc"]
also works.$endgroup$
– C. E.
1 hour ago
add a comment |
$begingroup$
Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:
list = {1.234, a[2], {"Abc", 4/5}, "acb"};
ToLowerCase[list]
(* Out: {ToLowerCase[1.234], ToLowerCase[a[2]], {"abc", ToLowerCase[4/5]}, "acb"} *)
That should not bother you though; it certainly does not bother Position
:
Position[ToLowerCase[list], "abc"]
(* Out: {{3, 1}} *)
$endgroup$
add a comment |
$begingroup$
Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:
list = {1.234, a[2], {"Abc", 4/5}, "acb"};
ToLowerCase[list]
(* Out: {ToLowerCase[1.234], ToLowerCase[a[2]], {"abc", ToLowerCase[4/5]}, "acb"} *)
That should not bother you though; it certainly does not bother Position
:
Position[ToLowerCase[list], "abc"]
(* Out: {{3, 1}} *)
$endgroup$
add a comment |
$begingroup$
Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:
list = {1.234, a[2], {"Abc", 4/5}, "acb"};
ToLowerCase[list]
(* Out: {ToLowerCase[1.234], ToLowerCase[a[2]], {"abc", ToLowerCase[4/5]}, "acb"} *)
That should not bother you though; it certainly does not bother Position
:
Position[ToLowerCase[list], "abc"]
(* Out: {{3, 1}} *)
$endgroup$
Note that ToLowerCase does not evaluate if the input is not a string, but it is Listable, so it will thread over your list:
list = {1.234, a[2], {"Abc", 4/5}, "acb"};
ToLowerCase[list]
(* Out: {ToLowerCase[1.234], ToLowerCase[a[2]], {"abc", ToLowerCase[4/5]}, "acb"} *)
That should not bother you though; it certainly does not bother Position
:
Position[ToLowerCase[list], "abc"]
(* Out: {{3, 1}} *)
answered 19 mins ago
MarcoBMarcoB
38.2k556114
38.2k556114
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194280%2ffind-non-case-sensitive-string-in-a-mixed-list-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown