Python Solution of sorting and searching part