I want to sort some items in a specific data structure, But I will try to generalize the problem I am stuck with
My input is a list that contains string items, I am expecting three items as in here, But it won't be necessarily three all the time. But even though I wanna sort it
My input contain either
a=['BHR','BHT','BHZ']
or
a=['BHN','BHE','BHZ']
Perhaps Instead of BH* we can expect anything but we only focus on the last letter.
either it will be 'Z,R,T' pair or 'Z,N,E' pair, the process should be stopped if it is in any other combination.
The output should be in the order of.
a=['Z','R','T']
or
a=['Z','N','R']
The output should be like this in order-wise even though there is no three items in the list
def sorter(a):
n=len(a)
for i in np.arange(0,n):
if (a[i].find('Z') == 1):
a0=a[i]
continue
elif (a[i].find('R') == 1):
a1=a[i]
continue
elif (a[i].find('T') == 1):
a2=a[i]
continue
a[0]=a0
a[1]=a1
a[2]=a2
Can anyone help me to finish this code? or suggest me a simple and effective alternate method?
NB: I would like to save the items in individual variables a0,a1,a2 and combine them later.