[Solved] calculate and return the difference between the second largest number and the second smallest number [closed]

Here is a simple, but not most efficient way. you can achieve that by two step: convert list to set, to remove the duplicate number. use heap to find nlargest and nsmallest in set def difference(list1): set1 = set(list1) return heapq.nlargest(2, set1)[1] – heapq.nsmallest(2, set1)[1] Here is a one pass way, more efficient way, use … Read more