a = ['123b4', '234v5', 'lobf56']
b = [obj1, obj2, obj3] # where each obj is list of object which has attribute called 'serial' which matches serial numbers in list #a
Where obj1.serial is 234v5, obj2.serial is lobf56 and obj3.serial is 123b4
tmplist=list()
for each in a:
for obj in b:
if each == obj.serial:
tmplist.append(obj)
print(tmplist)
output: [obj3, obj1, obj2]
I am currently able to achieve the sorting in above manner. But is there a better way to do it?