Comment extraire des éléments d'une liste d'une autre liste avec des correspondances partielles avec des éléments d'une troisième liste ?J'ai les listes suivantes
bigList = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1 = {"CD_CORN_", "CD_CORN_", "CD_CORN_"}; //note these are repeats and that is how I get them
smallList2 = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3 = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};en utilisant grande liste et petite liste1 , Je veux obtenir
sbigList1 = {"CD_CORN_1", "CD_CORN_2"};
en utilisant grande liste et petite liste2 , Je veux obtenir
sbigList2 = {"ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2"};en utilisant grande liste et petite liste3 , Je veux obtenir
sbigList3 = {"IPEK21_S00R_P37_2", "CURR_S009_P37_2", "Ig_RF", "Cmax03_4C230RF", "NG"};Comment faire cela via JSL ?
(l'ordre des éléments dans la sbiglist n'a pas d'importance)
Automatisation et scriptsles fenêtresRe : Comment extraire des éléments d'une liste d'une autre liste avec des correspondances partielles avec des éléments d'une troisième liste ?Voici comment je procéderais
Names default to here(1);
bigList = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1 = {"CD_CORN_"}; //note these are repeats and that is how I get them
smallList2 = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3 = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};
foundList = {};
For Each( {theList}, bigList,
For Each( {sublist}, smallList1,
if(contains(theList,sublist),
insert into(foundlist, theList)
)
);
For Each( {sublist}, smallList2,
if(contains(theList,sublist),
insert into(foundlist, theList)
)
);
For Each( {sublist}, smallList3,
if(contains(theList,sublist),
insert into(foundlist, theList)
)
);
);
Chaque élément distinct de bigList doit être évalué séparément.
Re : Comment extraire des éléments d'une liste d'une autre liste avec des correspondances partielles avec des éléments d'une troisième liste ?Je créerais très probablement une fonction pour quelque chose comme ça
Names Default To Here(1);
bigList = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1 = {"CD_CORN_", "CD_CORN_", "CD_CORN_"};
smallList2 = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3 = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};
get_partial_matches = function({to_list, with_list}, {Default Local},
/*""" Get partial matches to_list using with_list
Args:
from_list (list(str)): list to compare to
to_list (list(str)): list to compare with
Returns:
list(str): List with partial matches in alphabetical order
"""*/
matches = Associative Array(); // associative array to avoid duplicates
For Each({to_item}, to_list,
For Each({with_item}, with_list,
If(Contains(to_item, with_item),
Insert Into(matches, to_item);
);
);
);
return(matches << get keys); // << get keys to get result in a list
);
list1 = get_partial_matches(bigList, smallList1);
list2 = get_partial_matches(bigList, smallList2);
list3 = get_partial_matches(bigList, smallList3);
show(list1, list2, list3);
une autre option serait quelque chose comme ça, mais je préférerais de loin utiliser la précédente
get_partial_matches2 = function({to_list, with_list}, {Default Local},
matches = Associative Array();
pattern = Concat Items(with_list, "|");
For Each({to_item}, to_list,
res = Regex(to_item, pattern);
If(!IsMissing(res),
Insert Into(matches, to_item);
);
);
return(matches << get keys);
);
list1 = get_partial_matches2(bigList, smallList1);
list2 = get_partial_matches2(bigList, smallList2);
list3 = get_partial_matches2(bigList, smallList3);
show(list1, list2, list3);