fork download
  1. def second_largest(nums):
  2. if len(set(nums)) < 2:
  3. return None
  4. unique_nums = list(set(nums))
  5. unique_nums.sort()
  6. return unique_nums[-2]
  7.  
  8. # Example Usage
  9. print(second_largest([4, 2, 6, 6, 2, 1])) # Output: 4
  10. print(second_largest([7])) # Output: None
Success #stdin #stdout 0.02s 9700KB
stdin
Standard input is empty
stdout
4
None