Second Largest number in a Python List

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 พ.ย. 2024

ความคิดเห็น • 13

  • @empowercode
    @empowercode 3 ปีที่แล้ว +2

    Hey Programming Portal, nice to meet you! I just found your channel, love what you're doing!
    I like how clear and detailed your explanations are as well as the depth of knowledge you have surrounding the topic! Since I run a tech education channel as well, I love to see fellow Content Creators sharing, educating, and inspiring a large global audience. I wish you the best of luck on your TH-cam Journey, can't wait to see you succeed! Your content really stands out and you've put so much thought into your videos!
    Cheers, happy holidays, and keep up the great work ;)

  • @kvelez
    @kvelez ปีที่แล้ว

    data = [55,1,45,68,159,75,5,14]
    def find_max(data, i, value):
    if i >= len(data) - 1:
    return value
    if isinstance(data[i], int):
    if data[i] > value:
    value = data[i]
    return find_max(data, i+1, value)
    print(find_max(data, 0, 0))

  • @thilagawathis3997
    @thilagawathis3997 2 ปีที่แล้ว

    Super.. Also provide second smallest in a list program

  • @namita4678
    @namita4678 ปีที่แล้ว

    Please write code for second smallest number, if i already find first smallest number

  • @sindhumadhyala5961
    @sindhumadhyala5961 3 ปีที่แล้ว

    Could you please this code in while loop

  • @PankajKumar-ut8hh
    @PankajKumar-ut8hh 2 ปีที่แล้ว +1

    not working for this kind of input for list1= 6,6,-6,6 or list2=6,6,6,6,6,6,5

    • @sunnythapa9258
      @sunnythapa9258 ปีที่แล้ว

      ya also 57,57,-57,57

    • @TheProgrammingPortal
      @TheProgrammingPortal  ปีที่แล้ว

      Hi, this is because we explicitly explained that the second largest number should not be the same as the first largest in the video. But if you want to implement with such scenarios, change the below line, which enforces the above validation.
      Change this
      elif list[i] > second_max and first_max !=list[i]:
      To
      elif list[i] > second_max:
      Hope this helps.

  • @niravparekh1132
    @niravparekh1132 ปีที่แล้ว

    def find_max_min_number(array):
    largest_num=array[0]
    second_largest_num=0
    for i in array:
    if i > largest_num:
    largest_num=i
    print("Largest number is:",largest_num)
    for i in array:
    if i > second_largest_num and i !=largest_num:
    second_largest_num=i
    print("Second Largest Number:=",second_largest_num)
    array_range=int(input("Enter Array Range:"))
    loop_counter=0
    nums=[]
    for i in range(array_range):
    loop_counter+=1
    print(loop_counter,end=" ")
    element=int(input("Enter Array Element:"))
    nums.append(element)
    array=[]
    for i in nums:
    if i not in array:
    array.append(i)
    print('Remove All Dublicates:',array)
    find_max_min_number(array)

  • @archanakavya6334
    @archanakavya6334 ปีที่แล้ว

    code to find second smallest number in list
    l = [1,2,3,4,5,0]
    first = min(l[0],l[1])
    sec = max(l[0],l[1])
    for i in range(2,len(l)):
    if l[i] < first:
    sec = first
    first = l[i]
    elif l[i] < sec and first != l[i]:
    sec = l[i]
    print(sec)

  • @amanyadav-l4m8f
    @amanyadav-l4m8f 2 หลายเดือนก่อน

    bohot ganda hai

  • @sindhumadhyala5961
    @sindhumadhyala5961 3 ปีที่แล้ว

    Could you please this code in while loop

    • @TheProgrammingPortal
      @TheProgrammingPortal  3 ปีที่แล้ว +2

      You can change for loop to while loop similar to below code.
      Ref code is just snippet, please write full code. Hope this helps.
      for i in range(2, len(list1)):
      To
      i=2
      While i