[Solution] Python Lists Intermediate Questions | Class 41 | Python (Core & Advance) Course

Поделиться
HTML-код
  • Опубликовано: 22 ноя 2024
  • НаукаНаука

Комментарии • 27

  • @ashishvats1515
    @ashishvats1515 8 месяцев назад +1

    """
    Question: Write a program to find the average of all the numbers present in the list.
    """
    my_list= [88, 32, 12, 1, 99, 56, 78, 5, 8, 110]
    total = 0
    avg = 0
    for i in my_list:
    total= total+i
    print(f"Sum of list: {total}")
    avg = total/len(my_list)
    print(f"Average of all numbers present in list: {avg}")

    • @mohdadum3801
      @mohdadum3801 4 месяца назад

      list = [2,34,5,6,7,8]
      total = 0
      for i in range(len(list)):
      total = total + list[i]
      average = total / len(list)
      print(average)

  • @Kushaa17
    @Kushaa17 4 месяца назад

    Q120) input from user
    n=int(input())
    l=[]
    for i in range(0,n):
    a=int(input())
    l.append(a)
    l[0],l[-1]=l[-1],l[0]
    print(l)

  • @sachinjondhale6480
    @sachinjondhale6480 8 месяцев назад +1

    #119 Solution:
    my_list = [54, 32, 17, 67, 43, 11, 87, 44, 54, 32]
    list1 = []
    list2 = list1
    for i in range(0, int(len(my_list) / 2)):
    list1.append(my_list[i])
    print(list1)
    for i in range(int(len(my_list) / 2), len(my_list)):
    list2.append(my_list[i])
    print(list2)

  • @M_Bilal_14
    @M_Bilal_14 10 месяцев назад +1

    question--120
    user = [32, 10, "bilal", 90.5, "xyz"]
    #print(user)
    if len(user) >= 2:
    user[0], user[-1] = user[-1], user[0]
    print(user)

  • @Kushaa17
    @Kushaa17 4 месяца назад

    Q119) #taking input from user
    n= int(input())
    l=[]
    r1=[]
    r2=[]
    for i in range(0,n):
    a=int(input())
    l.append(a)
    if len(l)%2==0:
    for num in range(1,int(n/2)+1):
    r1.append(num)
    for num in range(int(n/2)+1,n+1):
    r2.append(num)
    else:
    for num in range(1,int((n+1)/2)+1):
    r1.append(num)
    for num in range(int((n+1)/2)+1,n+1):
    r2.append(num)
    print(l)
    print(r1)
    print(r2)

  • @alok707
    @alok707 3 месяца назад

    Q.119.
    one = [88, 89, 98, 77, 5, 77, 4]
    middle_index = len(one) // 2
    half1 = []
    half2 = []
    for i in range(0, middle_index):
    half1.append(one[i])
    for i in range(middle_index, len(one)):
    half2.append(one[i])
    print(half1)
    print(half2)

  • @ronnieee24
    @ronnieee24 11 месяцев назад +1

    120) Write a program that swaps the first and last elements of a given list.
    # lst = [4, 56, 11, "Ronnie", True, 0.142, -87]
    # print("Original list", lst)
    # first_element = lst[0]
    # last_element = lst[-1]
    # lst[0] = last_element
    # lst[-1] = first_element
    # print("Swapped list", lst)

    • @codeanddebug
      @codeanddebug  11 месяцев назад

      Perfect, you can even do using 1 variable also.
      temp = lst[-1]
      lst[-1] = lst[0]
      lst[0] = temp

    • @sachinjondhale6480
      @sachinjondhale6480 8 месяцев назад

      first_val = my_list[0]
      my_list[0] = my_list[-1]
      my_list[-1] = first_val
      print(my_list)@@codeanddebug

  • @Shantanu_lrnr
    @Shantanu_lrnr 11 месяцев назад

    Q 120................................Swap first and last element of the given list
    num = [1,2,3,4,5,6]
    num[0],num[-1] = num[-1],num[0]
    print(num)

  • @ashishvats1515
    @ashishvats1515 8 месяцев назад

    """
    Question119: Write a program to split a given list into two halves
    input_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    OUTPUT:
    first_half = [1, 2, 3, 4, 5]
    second_half = [6, 7, 8, 9, 10]
    """
    input_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    first_half = []
    second_half = []
    d = int((len(input_list))/2)
    print(d)
    for i in range(0,len(input_list)):
    if i < d:
    first_half.append(input_list[i])
    else:
    second_half.append(input_list[i])
    print(f"First half: {first_half}")
    print(f"Second half: {second_half}")

  • @KRAFTGAMIN
    @KRAFTGAMIN 10 месяцев назад

    #swap 4 with 11 and vice versa
    lst = [4, 56, 11, "Ronnie", True, 0.142, -87]
    pe1 = lst[0]
    pe2 = lst[2]
    v1 =lst.index(4)
    v2 =lst.index(11)
    lst[v1] = pe2
    lst[v2] = pe1
    print(lst)

    • @KRAFTGAMIN
      @KRAFTGAMIN 10 месяцев назад

      Why is this not working
      #swap 4 with 11 and vice versa
      lst = [4, 56, 11, "Ronnie", True, 0.142, -87]
      pe1 = lst[0]
      pe2 = lst[2]
      lst[lst.index(4)] = pe2
      lst[lst.index(11)] = pe1
      print(lst)

  • @ashishvats1515
    @ashishvats1515 8 месяцев назад

    """
    Question 120: Write a program that swaps the first and last elements of given list.
    my_list = [32,10,"Ashish",55.90,"xyz"]
    OUTPUT:
    ["xyz",10,"Ashish",55.90,32]
    """
    my_list = [32,10,"Ashish",55.90,"xyz"]
    first= my_list[-1]
    #print(first)
    last=my_list[0]
    #print(last)
    my_list[0] = first
    my_list[-1] = last
    print(my_list)

  • @ashishvats1515
    @ashishvats1515 8 месяцев назад

    """
    Question: Take 10 integers input from user and store them in a list.Now,
    copy all elements in another list but in reverse order
    """
    my_list = []
    reverse_list = []
    for i in range(1,11):
    my_list.append(int(input(f"Enter {i} number: ")))
    print(f"Your List: {my_list}")
    my_list.reverse()
    print(f"Reverse List: {my_list}")
    my_list.sort(reverse=True)
    print(f"List in Descending Order: {my_list}")

  • @M_Bilal_14
    @M_Bilal_14 10 месяцев назад

    question 119:
    user = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    res = len(user) // 2
    frist = user[:res]
    last = user[res:]
    print(frist)
    print(last)

  • @KRAFTGAMIN
    @KRAFTGAMIN 10 месяцев назад

    list = [100 ,300]
    n1,n2 = list #list upacnking
    p1 = n2 #storing in temp variable
    p2 = n1
    new = []
    new.insert(0,p1) #inserting as per postion
    new.insert(1,p2)
    print(new)

  • @Shantanu_lrnr
    @Shantanu_lrnr 11 месяцев назад

    Q 119....
    my_list = [1,2,3,4,5,6]
    a = len(my_list)//2
    print(f"First_half = {my_list[:a]}")
    print(f"Second_half = {my_list[a:]}")
    Sir,is it optimised solution???

  • @ashuanand52
    @ashuanand52 11 месяцев назад

    swapping first and last elements in a list
    a=[1,2,3,4,5,6]
    first=a.pop(0)
    last=a.pop(-1)
    a.append(first)
    a.insert(0,last)
    print(a)

  • @ashuanand52
    @ashuanand52 11 месяцев назад

    splitting a list into two halves
    a=[1,2,3,4,5,6]
    k=int(len(a)/2)
    first_half=[]
    second_half=[]
    for i in range(0,k):
    first_half.append(a[i])
    for i in range(k,len(a)):
    second_half.append(a[i])
    print(first_half)
    print(second_half)

  • @ronnieee24
    @ronnieee24 11 месяцев назад

    Q119 ka solution bata do sir?

    • @codeanddebug
      @codeanddebug  11 месяцев назад

      First loop from 0 to len(my_list)//2

  • @sairamarajubhukya2230
    @sairamarajubhukya2230 11 месяцев назад

    pop corn with cokeGood evening sir💥

  • @ashishvats1515
    @ashishvats1515 8 месяцев назад

    Hello sir, could you please check my Q.116 code :
    """
    Question: Write a python code to find the second largest element in a list without sorting.
    my_list= [54,32,17,67,43,11,87,44,54,32]
    """
    my_list= [54,32,17,67,43,11,87,44,54,32]
    sorted_list = []
    for i in range(0,len(my_list)):
    for j in range(i+1,len(my_list)):
    if my_list [i]