lst = [202, 165, 89, 76, 12] number_to_insert = 10 for i, num in enumerate(lst): if num
@AbhinavShukla-ki5jd3 ай бұрын
A bettery way? lst=[5,18,77,108,930] number=9 print(lst) for i in range(len(lst)): if number
@JyotiRanjanMohanty-v1s8 ай бұрын
#Assignment: Insert number in such a way that list is sorted in Descending order lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for num in lst: if num < number_to_insert: index = index else: index += 1 lst.append('None') for i in range(len(lst)-1,index,-1): lst[i] = lst[i-1] lst[index] = number_to_insert print(lst) Hi @Manish, Is there any optimized way to traverse , lets say if i've a list of 10k element, then here traversing will take more time.
@pharas_tech2 ай бұрын
lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for number in lst: if number < number_to_insert: index = index break else: index +=1 lst.append(None) for i in range(len(lst)-1,4,-1): lst[i]= lst[i-1] lst[index] = number_to_insert print(lst)
@VivekKhare-z1m3 ай бұрын
Assignment: lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for number in lst: if number < number_to_insert: index = index break else: index = index + 1 lst.append(None) for insert_value in range(len(lst)-1,index,-1): lst[insert_value] = lst[insert_value - 1] lst[index] = number_to_insert
@reshmabehera22319 күн бұрын
number_to_insert=15 lst=[202,165,89,76,12] print(lst) index=0 number_of_rec=len(lst) print(number_of_rec) for index in range(number_of_rec,0,-1): if lst[index-1] < number_to_insert: index= index-1 else: break print(index) lst.append(None) print(lst) for i in range(number_of_rec,index,-1): if i > index: lst[i] = lst[i-1] else: break lst[index] = number_to_insert print(lst)
@sarveshkumar-tq4fn6 ай бұрын
# Inserting Element in List lst = [18,86,77,102,730] inserted_number = 100 index = 0 for num in lst: if(num>inserted_number): index = index break else: index = index + 1 lst.append(None) for i in range(len(lst)-1,index,-1): lst[i] = lst [i-1] lst[index] = inserted_number logging.info(lst)
@yashiyengar73665 ай бұрын
lst = [202,165,89,76,12] num_insert = 120 index = len(lst)-1 for i in range(len(lst)-1,-1,-1): if lst[i] > num_insert: index = index break else: index -=1 lst.append(None) index +=1 for j in range(len(lst)-1,index,-1): lst[j] = lst[j-1] lst[index] = num_insert print(lst)
@kumarankit2302Ай бұрын
from loguru import logger lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for i in lst: if i > number_to_insert: index = index + 1 else: index = index break lst.append(None) for i in range(len(lst)-1, index, -1): lst[i] = lst[i-1] lst[index] = number_to_insert print(lst)
@gazalaamin50762 ай бұрын
Considering all the corner cases or edge cases: list1 = [5,18,75,108,930] # list1 = [] val = int(input("Enter the value to insert: ")) logger.info(f"The list is: {list1}") index = 0 if list1 == []: #When list is empty logger.info(f"The list is empty") list1 = val else: for i in range(len(list1)): #when inserting value is between the list elements or smallest value if val < list1[i]: list1.insert(i,val) break else: index = i continue if index == len(list1)-1: #When inserting value is the greater than the other list elements list1.append(val) logger.info(f"The new sorted list is: {list1}")
@raajnghani8 ай бұрын
index = 0 number_to_insert = 15 lst = [202,165,89,76,12] for number in lst: if number
@AnuragRaut-ry2oq4 ай бұрын
# Assignment lst = [202, 165, 89, 76, 12] index = 0 number_to_insert = 15 for number in lst: if number < number_to_insert: index = index else: index +=1 print(index) lst.append(None) for i in range(len(lst)-1,index,-1): lst[i] = lst[i-1] lst[index] = number_to_insert logger.info(f"new list {lst}")
@nabyenduKuiti4 ай бұрын
How to practice loop ?
@manish_kumar_14 ай бұрын
Geeks for geeks website
@vishnu0000018 ай бұрын
lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for i in lst: if i > number_to_insert: index = index +1 else: break print(index) lst.append("None") print(lst) for j in range(len(lst)-1,index,-1): lst[j] = lst[j-1] lst[index] = number_to_insert print(lst)
@divyaborse58666 ай бұрын
list1 =[202,165,89,76,12] target =15 pos=0 if len(list1)==0: list1.append(target) elif len(list1) == 1 and list1[0] < target: list1.append(list1[0]) list1[0] =target elif len(list1) == 1 and (list1[len(list1)-1] > target or list1[0] > target): list1.append(target) else: for i in range(len(list1)): if list1[i] < target: pos= i break print(pos) list1.append(None) print(len(list1)) for i in range(len(list1)-1,pos-1,-1): list1[i] =list1[i-1] list1[pos]= target print(list1)
@satyamkumarjha41854 ай бұрын
8
@anubhavsharma94498 ай бұрын
why you deleted pyspark playlist?
@ShubhamRai068 ай бұрын
Hai to bhai, kaha delete ki ,
@vinu11sharma6 ай бұрын
# 1st Way lst = [12, 76,89,165,202] lst.append(15) lst.sort() print(lst) #2nd Way lst_1 = [12, 76,89,165,202] index=0 logger.info(f" index value is {index} List Value is {lst_1}") for i in range(len(lst_1)-1): if lst_1[i]>120: index=index logger.info(f"if loop value i is {i} and index value is {index}") else: index=index+1 logger.info(f"Else loop value i is {i} and index value is {index}") lst_1= lst_1 + [None] print(lst_1) for j in range(len(lst_1)-1,index,-1): print(f"J value is: {j}") print(f"list value is: {lst_1[j]}") lst_1[j]=lst_1[j-1] print(lst_1) lst_1[index]=120 print(lst_1)
@abhinavsingh28945 ай бұрын
# Assignment Problem lst = [202,165,89,76,12] number_to_insert = 15 # Insert the number 15 in such a way that list is sorted in desending order. index = 0 # finding the index of the place where number needs to be added for number in lst : if number < number_to_insert: index = index break else: index = index +1 logger.info(index) lst.append(None) logger.info(lst) # [202, 165, 89, 76, 12, None] # traversing the list for i in range(len(lst)-1,index,-1): # (5,4,-1) lst[i] = lst[i-1] lst[index] = number_to_insert logger.info(lst)
@anmolg2886 ай бұрын
from loguru import logger list=[202,165,89,76,12] index=0 num_insert=15 list_asc=list[::-1] for i in list_asc: if i>num_insert: index=index break else: index=index+1 list_asc.append(None) logger.info(list_asc) for j in range (len(list_asc)-1,index,-1): list_asc[j]=list_asc[j-1] list_asc[index]=num_insert list_asc1=list_asc[::-1] logger.info(list_asc1)
@karandoke113428 күн бұрын
lst = [202,165,89,76,12] number_to_insert = 15 index = 0 for number in lst: if number