I have a tuple as given below
all_combi= [
('a', 33.333333333333336),
('a', 38.333333333333336),
('a', 43.333333333333336),
('a', 48.333333333333336),
('a', 53.333333333333336),
('a', 58.333333333333336),
('a', 63.333333333333336),
('a', 68.33333333333334),
('a', 73.33333333333334),
('a', 78.33333333333334),
('a', 83.33333333333334),
('a', 88.33333333333334),
('a', 93.33333333333334),
('a', 98.33333333333334),
('b', 33.333333333333336),
('b', 38.333333333333336),
('b', 43.333333333333336),
('b', 48.333333333333336),
('b', 53.333333333333336),
('b', 58.333333333333336),
('b', 63.333333333333336),
('b', 68.33333333333334),
('b', 73.33333333333334),
('b', 78.33333333333334),
('b', 83.33333333333334),
('b', 88.33333333333334),
('b', 93.33333333333334),
('b', 98.33333333333334),
('c', 33.333333333333336),
('c', 38.333333333333336),
('c', 43.333333333333336),
('c', 48.333333333333336),
('c', 53.333333333333336),
('c', 58.333333333333336),
('c', 63.333333333333336),
('c', 68.33333333333334),
('c', 73.33333333333334),
('c', 78.33333333333334),
('c', 83.33333333333334),
('c', 88.33333333333334),
('c', 93.33333333333334),
('c', 98.33333333333334)]
I want to sort this tuple based on this list
instr_list. = ['a', 'b', 'c']
The sample of the expected output is given below
[[
('a', 33.333333333333336),
('b', 33.333333333333336),
('c', 33.333333333333336)
], [
[('a', 33.333333333333336),
('b', 38.333333333333336),
('c', 43.333333333333336)]
]]
I tried the following solution given at here to sort a tuple based on list. But it doesnt give the desired outcome. I tried using explicit loop but it doesnt work. Any help is appreciated...
def get_slab_list(all_combi, instr_list):
out_master_list = []
for i in range(len(instr_list)):
#k=0
out_list=[]
for j in all_combi:
if j[0] == instr_list[i]:
out_list.append(j[1])
out_master_list.append(out_list)
return out_master_list
sample = get_slab_list(all_combi, instr_list)