I was wondering if there is a better way to solve this issue.
I have a list like this:
imp_list=["aa","daa","ab","as","aem", "aum","aw","aa","acm","at", "ar","aa_imp","daa_imp","ab_imp", "as_imp"]
I want to select all the strings that have the
_imp suffix, plus all the the strings that have no
aa_imp it's just a modified version of
aa, and for me, in a large sense, it's a replica.
So I created this function:
def imputed_handler(my_list): imp=[x for x in my_list if "imp" in x] cleaned_imp=set(map(lambda x: x.replace("_imp",""),imp)) not_imp=[x for x in my_list if "imp" not in x] set_list=set(my_list) no_replica=list(set_list-cleaned_imp) print(no_replica) return no_replica
Running the code as described above
I get the following output:
['at', 'acm', 'aw', 'ar', 'daa_imp', 'aem', 'as_imp', 'ab_imp', 'aa_imp', 'aum']
Do better solutions exist? Thanks for your time, and let me know if something is not clear :)
not_impand then never uses it :-P \$\endgroup\$