keep a list `datalist` of lists sorted as it is created by second element,dataList.sort(key=lambda x: x[1])