22Second Largest

    Mediumlistssets

    Write second_largest(nums) that returns the second largest distinct value in nums.

    If there is no such value (an empty list, or all values equal), return None.

    Examples

    Example 1
    >>> second_largest([3, 1, 4, 1, 5])
    4
    Example 2
    >>> second_largest([7, 7, 7])
    None

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write second_largest in the editor, then run the examples. Use print() freely: its output is shown for each test.