How do I split the elements in this element based on the string before the dot without explicitly writing it in code?
lst = ['ds_a.cola','ds_a.colb','ds_b.cola','ds_b.colb']
Since there are two variants of 'ds'. I want two lists.
lst_dsa = ['ds_a.cola','ds_a.colb']
lst_dsb = ['ds_b.cola','ds_b.colb']
My old code was:
lst_dsa = []
lst_dsb = []
for item in lst :
if "ds_a" in item:
lst_dsa.append(item)
else:
lst_dsb.append(item)
But I can't use this since there might be more than 2, like, ds_c,ds_d.... How do I achieve this in python?