I have a functions that returns cases from a table that match specific strings.
Once I get all the cases that match those strings, I need to search each case (which is its own list) for specific strings and do a Which command. But all I know how to do is turn the whole big list of lists into one string, and then I only get one result (when I need a result for each case).
UC@EncodeTable;
EncodeTable[id_?PersonnelQ, f___] :=
Cases[#,
x_List /;
MemberQ[x,
s_String /;
StringMatchQ[
s, ("*ah*" | "*bh*" | "*gh*" | "*kf*" |
"*mn*"), IgnoreCase -> True]], {1}] &@
Cases[MemoizeTable["PersonnelTable.txt"], {_, id, __}]
That function is returning cases from the table
Which[(StringMatchQ[
ToString@
EncodeTable[11282], ("*bh*" | "*ah*" |
"*gh*" ), IgnoreCase -> True]) == True, 1,
(StringMatchQ[
ToString@
EncodeTable[11282], ("*bh*" | "*ah*" |
"*gh*" ), IgnoreCase -> True]) == False, 0]
That function is SUPPOSED to return a 1 or 0 for each case returned by the first function, but I don’t know how to search within lists without making them all one string and return a result for each list.
Well, you probaby want
Map, but it’s hard to say without seeing what the structure of the data to be operated upon is. Perhaps you can provide an example.EDIT: In the comment, an example result was given as
(actually the example had a syntax error so I fixed it in what I hope is the right way).
Now, if I define a function
(note the second condition to be matched may be written as
True, see the documentation ofWhich) which does this(note that I’ve slightly changed
funcfrom what you have, in order for it to do what I assume you wanted it to actually do). This can then be applied todat, of which the elements have the form you gave, as follows:(*
-> {1, 1}
*)
I’m not sure if this is what you want, I did my best guessing.
EDIT2: In response to the comment about the position of the element to be matched being variable, here is one way:
so that
gives
{1,1}