Finding the Second Highest Number

  • Share this:

Code introduction


Find the second highest number in a list. If the list contains fewer than two elements, return None.


Technology Stack : List comprehension, sorting, indexing

Code Type : Function

Code Difficulty : Intermediate


                
                    
import array
import bisect
import calendar
import cmath
import contextlib
import csv
import datetime
import enum
import functools
import html
import http.client
import http.server
import imaplib
import json
import locale
import math
import multiprocessing
import os
import pickle
import queue
import random
import re
import socket
import statistics
import subprocess
import sys
import threading
import time
import traceback
import urllib.request
import urllib.parse
import urllib.error
import uuid

def find_second_highest(numbers):
    sorted_numbers = sorted(numbers)
    if len(sorted_numbers) < 2:
        return None
    second_highest = sorted_numbers[-2]
    return second_highest