Linear Search using Python | Python Tutorial for Beginners 68

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

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

  • @manikantaperumalla8014
    @manikantaperumalla8014 4 ปีที่แล้ว +170

    list=[4,3,12,34,56,77,89]
    n=int(input('enter a number'))
    for i in range(len(list)):
    if list[i]==n:
    print('found at pos',i+1)
    break
    else:
    print('not found')

    • @jevardhanpolemoni7730
      @jevardhanpolemoni7730 3 ปีที่แล้ว +1

      How would you know the position then?

    • @Mamata171
      @Mamata171 3 ปีที่แล้ว +1

      tq

    • @saikumarc4790
      @saikumarc4790 3 ปีที่แล้ว +7

      @@jevardhanpolemoni7730 for i in range(0,len(list))
      If list[i]==key:
      Return i
      Return -1

    • @vijaysatyamsetti3336
      @vijaysatyamsetti3336 3 ปีที่แล้ว +9

      @@jevardhanpolemoni7730 pos=-1
      num=int(input("enter a num: "))
      list=[5,8,4,6,9,2]
      i=0
      for i in range(len(list)):
      globals()['pos']=i
      if list[i]==num:
      print("found",pos)
      break
      else:
      print("not found")

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

      def search(list,n):

      for i in range(len(list)):
      if list[i] == n:
      return True
      return False

  • @findingyou6905
    @findingyou6905 6 ปีที่แล้ว +31

    Good work please keep uploading we are learning from you both javascript and python

  • @Skaxarrat
    @Skaxarrat 6 ปีที่แล้ว +6

    A simpler way to do the search function:
    def search(my_list, n):
    for i, num in enumerate(my_list):
    if num == n:
    globals()['position'] = i + 1
    return True

  • @mituldaniadventureJunkie
    @mituldaniadventureJunkie 5 ปีที่แล้ว +39

    list = [21,4,95,65,74,56]
    n=65
    def search(list,n):
    for i in list:
    if i==n:
    print("Value Found at " , list.index(i)+1)
    return True
    if search(list,n):
    print("Thank you")
    else:
    print("Value Not Found")
    Output : Value Found at 4
    Thank you

    • @myc007
      @myc007 5 ปีที่แล้ว

      Kuch b out put ni ata

    • @usaid4khan
      @usaid4khan 5 ปีที่แล้ว

      this code has a complexity of N^2, although your code is correct but it's not so efficient as compared to the code with a complexity of N.

    • @Prajwal_KV
      @Prajwal_KV 4 ปีที่แล้ว +1

      @@usaid4khan how n^2 ? we are using one for loop so 'n' and then another search list.index(i) now another 'n' that's why its n^2 right bro?

    • @Perplexedsouvik
      @Perplexedsouvik 4 ปีที่แล้ว

      This code is so efficient..can you tell me what is the name of the way we printed the position.

  • @SinghUjjwalKumar
    @SinghUjjwalKumar 5 ปีที่แล้ว +2

    l=[1,2,3,4,5]
    x=int(input("enter number to search in",l))
    i=flag=0
    while i

  • @nandinigangireddy6153
    @nandinigangireddy6153 ปีที่แล้ว +1

    tq sir,i like the way u teach
    lst=[2,4,5,6,7,8]
    n=int(input('enter which nmber u want to find index:'))
    for i in range(len(lst)):
    if(lst[i]==n):
    print('{} found at index {}'.format(n,i))
    break
    else:
    print('{} not found in the given list'.format(n))

  • @mrigankved
    @mrigankved 5 ปีที่แล้ว +32

    val = [2,1,4,7,3,8,9]
    valueTosearch = 6
    for i in range(len(val)):
    if val[i] == valueTosearch:
    print("Found the value at position", i+1)
    break
    else:
    print("Not Found in the list")

    • @mdbhardwaj5005
      @mdbhardwaj5005 4 ปีที่แล้ว

      Good solution but you are not defining any function. You have to use function (for practice purposes) at this level of learning.

    • @harendragoswami5893
      @harendragoswami5893 4 ปีที่แล้ว

      Actually, len function will give us the no of elements in the list , instead u should write "for i in val: "

  • @thedevelopersjourney57
    @thedevelopersjourney57 4 ปีที่แล้ว +51

    make videos on python DATA STRUCTURE PLEASE SIR(SEARCHING,SORTING,ALGORITHMS)

    • @jasonmarkakhtar4397
      @jasonmarkakhtar4397 3 ปีที่แล้ว +1

      yeah pls sir, plsss, my exam is on 25th so plss, sir

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

      Kya sir ne data structures pe video banayi kya can anyone pls tell me

    • @amitdwivedi8244
      @amitdwivedi8244 ปีที่แล้ว +1

      Yes sir pls make videos on DAta structure with python

  • @niharikam4744
    @niharikam4744 3 ปีที่แล้ว +25

    Telusko means to know in Telugu

    • @Whatsnew19742
      @Whatsnew19742 5 หลายเดือนก่อน +2

      Adhi telusko kaadhu bangaram thelusuko

  • @alokdubey4771
    @alokdubey4771 6 ปีที่แล้ว +7

    Good morning sir....sir this is first time I'm commenting on a TH-cam channel I have seen you teach better than our college teacher that's reason I'm kindly requesting to make video for students of bsc it regarding their projects for third year please sir show us a path please

  • @BoomcoreIsLive
    @BoomcoreIsLive 5 ปีที่แล้ว +40

    #simplestCode
    list,key=[1,2,3,4,5],3
    if key in list:
    print("found at index", list.index(key))
    else:
    print("not found")

    • @chococandy8009
      @chococandy8009 5 ปีที่แล้ว +2

      Yeah ! Absolutely correct.

    • @saunaknandi1814
      @saunaknandi1814 5 ปีที่แล้ว +2

      i also expect this method but why sir make it lenthier i cant undestand

    • @taruntosh7970
      @taruntosh7970 5 ปีที่แล้ว +2

      This performs 2 searches.
      For key in list
      And
      List.index(key)

    • @feynman8692
      @feynman8692 4 ปีที่แล้ว +2

      def search(list,n):
      for i in range(len(list)):
      if (list[i]==n):
      return True
      else:
      return False
      values={1,2,3,4,5}
      if search("values",1):
      print("found")
      else:
      print("not found")
      this program is not working .... every time it says "not found" even if the element is present

    • @ajaybhandari9215
      @ajaybhandari9215 4 ปีที่แล้ว

      @@feynman8692 for i in range(len(list)):

      if (list[i]==n):
      return True
      else:
      return False
      bro u cant use else here ....because everytime it is checking for list[i]==n and if it is not true it will move to else block and will return false that is not found ....even if it is found in the list

  • @apporvaarya
    @apporvaarya 4 ปีที่แล้ว +8

    Sir it's love.. ur teaching is love in this quartine.. best use of time

  • @GoogleMathtube
    @GoogleMathtube 5 ปีที่แล้ว +3

    from array import *
    f1 = array('i',[])
    x=int(input('enter the index'))
    for i in range(x):
    p=int(input('enter the elements'))
    f1.append(p)
    print(f1)
    r=int(input('enter the number'))
    for i in range(len(f1)):
    if(r == f1[i]):
    print('the number is found at ',i)
    else:
    print('not found')

  • @manjunathpatkar477
    @manjunathpatkar477 3 ปีที่แล้ว +1

    def Linearsearch(lst, n):
    s = 0
    for i in lst:
    s = s+1
    if i == n:
    print("found at", s-1)
    s= s+1
    break
    else: print('not found')
    lst = [2,9,8,7,6]
    n = 7
    Linearsearch(lst,n)

  • @gkr9375
    @gkr9375 4 ปีที่แล้ว

    pos=-1
    def lsearch(list,n):
    for i in list:
    if i< len(list):
    if list[i]==n:
    globals()["pos"]=i
    return True
    list=[5,8,4,6,9,2]
    n=2
    if lsearch(list,n):
    print("Found the number and the position is", pos)
    else:
    print("not found")

  • @ultimatetech_yt3739
    @ultimatetech_yt3739 ปีที่แล้ว +1

    list=[213,23423,5342,1231,1233]
    n=int(input("enter the number you want to find : "))
    for i in range(len(list)):
    if list[i]==n:
    print("FOUND")
    break
    else:
    print("not")

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

    Thanks a lot sir!
    pos = -1
    list = [10,20,30,40,50,60]
    n = int(input('enter a number'))
    for i in range(len(list)):
    if list[i] == n:
    globals()['pos'] = i
    print('found at no',pos)
    break
    else:
    print('not found')

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

      Add i=I+1 next to return true it's not incrementing

  • @yashgaur3763
    @yashgaur3763 4 ปีที่แล้ว +3

    assignment done sir !!!!
    Answer : if i in range(6):

    • @SanthoshKumar-fw4dz
      @SanthoshKumar-fw4dz 4 ปีที่แล้ว

      It's better to use stop as n in range like if i in range(n)

  • @zakiasmaa6834
    @zakiasmaa6834 4 หลายเดือนก่อน

    I want to express my heartfelt gratitude for all the effort you put into simplifying the topics. Your presence and the way you explain things in the videos bring us joy and radiate positive energy. I hope you continue in this way, and I wish you all the best in everything you do.

  • @painghtetaung6780
    @painghtetaung6780 5 ปีที่แล้ว +2

    def search(list, guess):
    for i in list:
    if i == guess:
    globals()['p'] = i
    return True
    return False
    list = [5,4,8,7,3,2]
    guess = int(input("Guess The Number(for loop method)"))
    if search(list, guess):
    print('Congratulation','Position is ->',list.index(p)+1)
    else:
    print('Not correct')

  • @PhoenixRisingFromAshes471
    @PhoenixRisingFromAshes471 6 ปีที่แล้ว +5

    Sir please don't quit python.............javascript is very good but we need your videos on python

  • @Kushagra123-y7e
    @Kushagra123-y7e 2 ปีที่แล้ว +1

    Telusko="best thing ever taught of"
    thank you sir i appreciate you hard work

  • @ankitabasu81
    @ankitabasu81 3 ปีที่แล้ว +10

    please do make a series on DSA with Python. Because sir, the way you explain things gives a complete different perspective and approach.

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

      this is the starting point of DSA in python

  • @shubham_singh9918
    @shubham_singh9918 2 ปีที่แล้ว +1

    def linear_search(array,n,x ) :
    For i in range(0,n) :
    If(array[i]==x :
    return i
    Return -1
    array=[1,2,89,9,5,7]
    N=len(array)
    X=5
    Result=linear_search(array, n,x)
    If result ==-1
    Print("Element to be not found")
    Else:
    Print(Element is found at)

  • @pratikrout1400
    @pratikrout1400 4 ปีที่แล้ว

    def search(list, n):
    global i
    i = 0
    while i < len(list):
    if list[i] == n:
    return True
    i += 1
    return False
    list = [4, 9, 7, 3, 2, 8]
    n = 7
    if search(list, n):
    print("Found at",i)
    else:
    print("Not Found")

  • @karthikkeyansmk2727
    @karthikkeyansmk2727 4 ปีที่แล้ว +1

    my assignment:
    at = 0
    def linerSearch(lst,n):
    for b in range(len(lst)):
    if lst[b] == n:
    globals()['at'] = b
    return True
    else:
    return False
    lis = [5,6,7,8,9]
    num = 9
    if linerSearch(lis,num):
    print("found",at+1)
    else:
    print("not found")

  • @golberts5844
    @golberts5844 4 ปีที่แล้ว +1

    def check (list,n):
    a = len(list)
    for i in range(a):
    if list[i] == n:
    return True
    return False
    list = [1,2,3,4,5]
    n = 6
    if check (list,n):
    print('matching')
    else :
    print('does not match')
    Is it correct sir ?

  • @muhammadmurad6340
    @muhammadmurad6340 4 ปีที่แล้ว +2

    This really helpful thank you.
    list1 = [12,23,45,23,67]
    Element_to_search = 23
    i = 0
    for x in list1:
    i += 1
    if x == Element_to_search:
    print(x)
    print("it is on")
    print(i)

  • @chandrimamazumdar3630
    @chandrimamazumdar3630 4 ปีที่แล้ว

    def search(l1,n):
    for i in range(len(l1)):
    if n==l1[i]:
    print("found at index {}".format(i))
    a=list(map(int,input("Enter numbers in list").split()))
    b=int(input("Enter the number you wanna search"))
    search(a,b)

  • @vinaymt6426
    @vinaymt6426 5 ปีที่แล้ว +3

    For i in range(len(list)):
    If list[i]==n:
    globals() ['pos']=i
    return True
    return false

  • @thamotharanm5612
    @thamotharanm5612 6 ปีที่แล้ว

    Awesome ...I doesn't hear like this from any people...such nice vedio about linear search 😍😍😍

  • @SeekAndFind
    @SeekAndFind 4 ปีที่แล้ว

    pos = -1
    file = [1,2,3,4,5,6,7,8,9]
    n = 8
    def search(x,y):
    for i in range(0,len(x)):
    if x[i]== n:
    globals() ["pos"] = i+1
    return True
    return False
    if search(file,n):
    print("Yes it is at",pos)
    else:
    print("No")

  • @vinoddiwan5792
    @vinoddiwan5792 5 ปีที่แล้ว +3

    Your voice, as well as style boost, encourage me to learn more

  • @prabalagrawal4058
    @prabalagrawal4058 4 ปีที่แล้ว

    Asnw of assignment:-
    pos=0
    def search(x,n):
    for i in range(len(x)):
    globals()['pos']=i+1
    if x[i]==n:
    return 'true'
    break
    else:
    return 'false'

    x=[1,2,3,4,5,6]
    n=6
    y=search(x,n)
    if y=='true':
    print('found',pos)
    else:
    print('not found')

  • @pratikburte5027
    @pratikburte5027 4 ปีที่แล้ว +1

    pos=-1
    def search(lis,n):
    for i in range(len(lis)):
    if lis[i]==n:
    globals()['pos']=i+1
    return True
    return False
    lis=[5,9,10,8,33,46,1,35,48,12,66]
    n=int(input('Enter the number which you want to search: '))
    print('List contains total of {} elements'.format(len(lis)))
    if search(lis,n):
    print('{} found at position {}'.format(n,pos))
    else:
    print('{} is not found anywhere in the list'.format(n))

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

    def funsearch(a,x):
    c=0
    for i in range(0,len(a)):
    if a[i]==x:
    print("Found Loaction=",i)
    c=c+1
    print("Frequency of element =",c)
    A1=eval(input('Enter a list'))
    B1=eval(input('Element to be searched'))
    funsearch(A1,B1)

  • @zxzxzy
    @zxzxzy 4 ปีที่แล้ว

    One way of searching using for loop
    def Mysearch(list,n):
    for i in range(len(list)):
    if list[i] == n:
    print('Found ' + str(n)+' at position ' + str(i+1))
    break
    else:
    print('Not Found')
    list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    Mysearch(list,5)
    Output : Found 5 at position 5

  • @chinmaydas4053
    @chinmaydas4053 6 ปีที่แล้ว +5

    As usual another great video sir 🙏🙏..

  • @rishithareddy8962
    @rishithareddy8962 3 ปีที่แล้ว +1

    Good Evening, Sir!
    I found this amazing video which cleared all my doubts.
    You just didn't sound like a Telugu guy.
    Thank you so much, Sir:)

  • @BoomcoreIsLive
    @BoomcoreIsLive 5 ปีที่แล้ว +1

    #linearSearch
    list=[1,2,3,4,5]
    key=5
    pos=0
    def search(list,key):
    global pos
    for i in list:
    if i==key:
    return True
    pos+=1
    else:
    return False
    if search(list,key):
    print("value found at list[%d]"%pos)
    else:
    print("value not found")

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

    Thanks from TamilNadu!

  • @maxon5153
    @maxon5153 4 ปีที่แล้ว +1

    from numpy import *
    def linearSearch(arr, key):
    for i in range(len(arr)):
    if key == arr[i]:
    return i
    else:
    return "Not found"
    arr = array([2,3,5,1,2,6])
    a = linearSearch(arr,7)
    print(a)

  • @ramswarooppoonia9655
    @ramswarooppoonia9655 6 ปีที่แล้ว

    thanks sir.......................
    pos=0
    def search(list, n):
    i=0
    for i in range(len(list)):
    if list[i]==n:
    globals()['pos']=i
    return True;
    return False;
    list=[5,17,8,15,12,9,1]
    n=int(input("Enetr a number to search:"))
    if search(list,n):
    print("Found",pos+1)
    else:
    print("Not match")

  • @jagajeevan4u584
    @jagajeevan4u584 4 ปีที่แล้ว

    short and easy with for loop
    def search(lst,n):
    for i in lst:
    if i == n:
    globals()['pos'] = lst.index(i)
    return True
    return False
    lst = [1,5,9,4,8,7,6,2,3]
    n = 7
    if search(lst,n):
    print("found at position", pos+1)
    else:
    print("not found")

  • @muhammedarshad1473
    @muhammedarshad1473 5 ปีที่แล้ว +4

    simple way
    without using func
    nums=[]
    x=int(input("how many numbers u want enter"))
    for k in range(x):
    nums.append(input())
    print("ur list is",nums)
    x=int(input('enter element u want to search'))
    for i in nums:
    if str(i)==str(x):
    print(x,"is in list at position",nums.index(i)+1)
    break
    else:
    print("not in list")

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

    def lin(a,n):
    for i in range (len(a)):
    if a[i]==n:
    pos=i
    print('elemt found at index',pos)
    lin([1,2,3,4,5,6],5)

  • @laljiprajapati9727
    @laljiprajapati9727 6 ปีที่แล้ว

    I found ans,Sir
    You can see
    def search(list,n):
    for i in range(len(list)):
    if list[i] == n:
    globals()['pos'] = i
    return True
    return False
    list = [5,8,4,6,9,2]
    n = 9
    if search(list,n):
    print('Found it',pos+1)
    else:
    print('Not Found')

  • @KiranKumar-pe3vl
    @KiranKumar-pe3vl 4 ปีที่แล้ว

    def search(lst,n):
    for i in range(len(lst)):
    if lst[i]==n:
    print("found at",i+1)
    break
    else:
    print("not f")
    lst=[1,2,3]
    search(lst,2)

  • @vishnukumarpaswan9053
    @vishnukumarpaswan9053 4 ปีที่แล้ว +1

    An another way: without using loop
    a=[1,4,6,3,8,9]
    b=6
    try:
    print( a.index(b))
    except Exception as e:
    print('no.not found')
    finally:
    print('thanks

  • @UzzyX
    @UzzyX หลายเดือนก่อน

    def linear_search(list, target):
    for i in range(len(list)):
    if list[i] == target:
    return i
    return -1
    list = [1,2,3,4,5,6,7,8,9]
    target = 7
    position = linear_search(list, target)
    if position != -1:
    print("found at", position)
    else:
    print("not found")

  • @EEBAsrithaDevineni
    @EEBAsrithaDevineni 4 ปีที่แล้ว

    def search(list,n):
    for i in range(len(list)):

    if list[i]==n:
    print('found',i)
    break
    else:
    print('notfound')
    list = [2,3,4,1,21]
    n = 3
    search(list,n)

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

    def linear_search(list,n):
    for i in range(len(list)):
    if list[i]==n:
    return ('found')
    return ('not found')
    li1= [5,7,3,1,4,8,6,2]
    num1=8
    linear_search(li1,num1)

  • @mannamkoushik8245
    @mannamkoushik8245 4 ปีที่แล้ว

    def linearsearch(arr, x):
    for i in range(len(arr)):
    if arr[i] == x:
    return i
    return -1
    arr = [1,2,3,4,5,6,7,8]
    x = 4
    print("element found at index "+str(linearsearch(arr,x)))

    • @Vivi24139
      @Vivi24139 4 ปีที่แล้ว

      i am not understanding this -1 why we use it can you please explain thanks and also the last print statement getting error

  • @vikramrajnampalli7610
    @vikramrajnampalli7610 4 ปีที่แล้ว +1

    Thank you Navin ...you made my day ....you are a champion mate and appreciate the work that is helping thousands ....

  • @anujmore7547
    @anujmore7547 4 ปีที่แล้ว

    We can also do it like this
    def search(l1, n):
    if n in l1:
    return True
    l1 = [10, 32, 22,652,45]
    print(l1)
    n = 32
    if search(l1, n):
    print("Found")
    else:
    print("Not found")

  • @christianihechi
    @christianihechi 5 หลายเดือนก่อน

    Thank you Telusko.
    def search(iterable, n):
    try:
    index = iterable.index(n)
    if n in iterable:
    print(f"{n} was found at position {index+1}.")
    except ValueError:
    print(f"Sorry, {n} is not in the list.")
    nums = [13, 45, 12, 19, 90, 0, 10]
    user = int(input("What would you like to search: "))
    search(nums, user)

  • @rohitreddy2893
    @rohitreddy2893 5 ปีที่แล้ว +1

    i = -1
    def search (list,n):
    for i in range(len(list)):
    if list[i] == n:
    globals()['i']=i
    return True
    list = [5,8,4,6,9,2]
    n = 9
    if search(list,n):
    print("Found at",i+1)
    else:
    print("Not Found")

    • @kamranansari4887
      @kamranansari4887 5 ปีที่แล้ว

      use p for position instead of i because i is already use by for loop as variable

  • @DauDoful
    @DauDoful 4 ปีที่แล้ว

    My sol for loop:
    pos=-1
    def search(list,n):
    for i in range(len(list)):
    if list[i]==n:
    globals()["pos"]=i
    return True
    return False
    list=[5,8,4,6,9,2]
    n = 9
    if search(list,n):
    print("Found at", pos+1)
    else:
    print("Not found")

  • @SanjayKumarK-um5no
    @SanjayKumarK-um5no ปีที่แล้ว

    from array import *
    list = array('i', [5, 8, 4, 6, 9, 2]) # array
    n = 10
    pos=0
    for i in range(len(list)):
    if n==list[i]:
    pos=i
    print("the element",n,"present at the index",pos)
    break
    else:
    print("the element", n, " is not present in the array")

  • @NAVEENKUMAR-ho5tw
    @NAVEENKUMAR-ho5tw 5 ปีที่แล้ว

    def search(x,y):
    for n in x:
    global a
    a=0
    if y==n:
    return True
    return False
    x=1,2,3,4
    y=int(input('enter the element to search'))
    if search(x,y):
    print('element found',a+1)
    else:
    print('not found')

  • @156_surajbhanarkar8
    @156_surajbhanarkar8 3 ปีที่แล้ว

    pos = -1
    def search (list ,n):
    #i=0
    #while i

  • @danielkamau8436
    @danielkamau8436 3 ปีที่แล้ว +1

    pos = -1
    def search_num(nums, num):
    i = 0
    for i in range(len(nums)):
    if nums[i] == num:
    globals()['pos'] = i
    print("found at: ", pos +1)
    else:
    print("no number")
    nums= [3,7,4,8,0,6]
    num = 3
    search_num(nums, num)

  • @TheShubham743
    @TheShubham743 5 ปีที่แล้ว

    loc=0
    def search(list,n):
    for i in range(len(list)):
    if list[i]==n:
    globals()['loc']=i
    return True
    return False
    list=[5,8,4,6,9,2]
    n=9
    if search(list,n):
    print('found at',loc+1)
    else:
    print('not found')

  • @lorizhuka6938
    @lorizhuka6938 6 ปีที่แล้ว +4

    can you please post videos about data science and machine learning?

  • @Kavitha-Manohar
    @Kavitha-Manohar 5 ปีที่แล้ว

    x = 5
    list = [1,2,3,4,5]
    for i in range(len(list)):
    if(list[i] == x):
    print("Item found at index " + str(i))
    elif(i >= len(list)-1):
    print("Item not found" + str(i))
    else:
    continue

  • @tejastj8753
    @tejastj8753 4 ปีที่แล้ว

    def search(list, n):
    for i in range(len(list)):
    if i == n:
    i-=1
    print(list[i])
    return list[i]
    list = [1,2,3,4,5,6,7,8]
    n = 3
    if search(list,n):
    print("found")
    else:
    print("not found
    invaild syntax")

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

    Sir,I have wrote a code by taking input from user for linear search using for loop
    p=0
    n=int(input('enter length of list '))
    a=[]
    for i in range(n):
    a.append(int(input('enter no ')))
    print(a)
    b=int(input('enter no u want to search '))
    def search(a,b):
    for i in range(len(a)):
    if a[i]==b:
    globals()['p']=i
    return True
    return False
    if search(a,b):
    print('found at ',p+1)
    else:
    print('not found')

  • @moazelsawaf2000
    @moazelsawaf2000 5 ปีที่แล้ว

    Assignment :
    def search(lst, n):
    for i in range(len(lst)):
    if lst[i] == n:
    print(i)
    return True
    return False
    l = [5, 8, 4, 6, 9, 2]
    value = 9 # the value we want to search for
    if search(l, value):
    print('Found')
    else:
    print('Not Found')

  • @smokeymusicalstudio2613
    @smokeymusicalstudio2613 3 ปีที่แล้ว +1

    pos = -1
    def search(list, n):
    if list[i]==n:
    globals()['pos'] = i
    return True
    return False
    List1 = [5, 8, 4, 6, 9, 2]
    n = 9
    if search(list1, n):
    print('Found')
    else:
    print('Not found')

  • @Arjun_Singh_Rana
    @Arjun_Singh_Rana 5 ปีที่แล้ว

    using for loop
    pos=-1
    def search(list,n):
    for i in range(len(list)):
    if list[i]==n:
    globals() ['pos'] = i
    return True
    else:
    return False
    list=[5,8,4,6,9,2]
    n=2
    if search(list,n):
    print("found at ",pos+1)
    else:
    print("not found ")

  • @GurpreetSingh-gq4hx
    @GurpreetSingh-gq4hx 3 ปีที่แล้ว +8

    # Program : Linear search with "For Loop"
    pos = 0
    def search(list, n):
    for i in list:
    if i == n:
    globals()['pos'] = list.index(n)
    return True
    return False
    list = [5,8,4,6,9,2]
    n = 9
    if search(list, n):
    print("Found at position", pos+1)
    else:
    print("Not Found")

  • @masterbuntykadam
    @masterbuntykadam 6 ปีที่แล้ว

    Maybe a little bit simpler:
    a=[1,5,9,7,8,3,13]
    n=8
    for each_num in a:
    if each_num==8:
    print (str(each_num)+" is present at:"+str(a.index(each_num)))
    else:
    print ("specified number is not present")

  • @itsmegiridhar
    @itsmegiridhar 5 ปีที่แล้ว

    pos = -1
    def search(list, n):
    i = 0
    for i in range(len(list)):
    if list[i] == n:
    globals()['pos'] =i
    return True
    list = [123, 45, 678, 456, 7876, 22345, 21]
    n = 21
    if search(list, n):
    print("Found at Position",pos+1)
    else:
    print("Notfound")

  • @rajeshprasad915
    @rajeshprasad915 5 ปีที่แล้ว

    def ls(l, n):
    for i in range(len(l)):
    if l[i] == n:
    print(f"found the value {n} at {i} ")
    break
    else:
    print("not found")
    l = [2,6,3,7,55,78,42,99]
    n = input("enter the value: ")
    ls(l, n)

  • @pritishchandhok6607
    @pritishchandhok6607 5 ปีที่แล้ว

    def search(lst,n):
    for i in range(0, 4):
    if lst[i] == n:
    print('t',i)
    i += 1
    break
    else:
    print('f')
    lst = [2,4,2,7,9]
    n=7
    s=search(lst,n)

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

    pos = 0
    def use_for_lop(lsit,value):
    for i in range(len(list)):
    if list [i] == value:
    globals()['pos']=i
    return True
    list = [1, 2, 3, 4, 5,6 ]
    value = 4
    if use_for_lop(list,value):
    print('found at ', pos +1)
    else:
    print('not found')

  • @Theknightriders
    @Theknightriders 4 ปีที่แล้ว +7

    Awesome tutorials. I liked watching tutorials. Planning to watch and learn all :) Again thanks for this wonderful video.

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

    Very good explanation 👏

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

    # LS
    # just made 2 changes accordingly
    pos = -1
    def search(list,n):
    for i in range(len(list)):
    globals() ['pos'] = i
    if list[i] == n:
    return True
    return False
    list = [1,3,6,9,10,4]
    n = 3
    if search(list, n ):
    print("found",pos)
    else:
    print("not found")

  • @himelacharjee5260
    @himelacharjee5260 5 ปีที่แล้ว

    # linear search
    pos = -1
    def search(list,n):
    i = 0
    #while i

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

    position = -1
    def linear(list, x):
    for i in range(len(list)):
    globals()['position'] = i
    if list[i] == x:
    return i
    return 0
    list = [2, 3, 78, 21, 67, 73, 43, 90]
    x = 78
    if linear(list, x):
    print("item is found at:", +position)
    else:
    print("item is not found..!")
    Output :-
    item is found at: 2

  • @MonolingualBeta
    @MonolingualBeta 6 หลายเดือนก่อน

    list = [7,9,9,1,7,4,8,5]
    num = int(input("search for the value"))
    print("The indexes of the value are:", end="")
    for i in range(0, len(list)):
    if list[i] == num:
    print(i, ",", end="")
    else:
    print("not found")
    Short and sweet, I hope

  • @utkarshsingh1584
    @utkarshsingh1584 6 ปีที่แล้ว

    pos=-1
    def search(list,n):
    for x in range (len(list)):
    if list[x]==n:
    globals()['pos']=x
    return True
    return False
    list=[3,2,5,6,9,8]
    n=9
    if search(list,n):
    print("Found",pos+1)
    else:
    print("Not Found")

  • @prasannakatre4040
    @prasannakatre4040 2 ปีที่แล้ว +1

    #Linear Search for a value in the list using for loop and function.
    indexposition = -1
    def search(list, n):
    for i in range(len(list)):
    if list[i] == n:
    globals()['indexposition'] = i
    return True
    else:
    return False
    list = [23,12,73,33,19]
    n = 19
    if search(list, n):
    print("Value is",n,"and is found at position no.", indexposition + 1 )
    else:
    print("Value is",n,"and Not found in the list, try again")

  • @banjosufa
    @banjosufa 9 หลายเดือนก่อน

    thank you for another wondeful lesson Navin!!
    just one question:
    i tryied this code without the 'pos = -1' in the beginning and it works all the same.. so why do we actually need it for? thanks 🙂

  • @lostman555
    @lostman555 5 ปีที่แล้ว

    pos = -1
    def search (list,n):
    for i in range (len(list)):
    if list[i]==n:
    globals()['pos'] = i
    return True
    else:
    return False
    try:
    n = int(input("Enter the integer number to find in list "))
    list = [2,4,1,5,7,8]
    if search(list,n):
    print ("found at position", pos)
    else:
    print ("not found")
    except:
    print ("Enter the valid integer")

  • @kislayraj3239
    @kislayraj3239 4 ปีที่แล้ว

    Def search (list,n):
    For i in range(len(list)):
    If list[i] == n:
    Print(" index" ,list.index(n))
    return true
    i += 1
    List = [1,2,3,4,5,6]
    N =5
    If search (list ,n):
    Print("found")
    Else:
    Print("Not Found ")

  • @souravnandy1308
    @souravnandy1308 5 ปีที่แล้ว

    def linear_search(data, target):
    for i in range (len(data)):
    if data[i] == target:
    return True
    return False
    data = [12,23,34,45,56,67,78,89,90]
    target = 56
    if linear_search (data, target):
    print("Found")
    else:
    print("Not Found")

  • @debolinamajumdar
    @debolinamajumdar 4 ปีที่แล้ว

    def LinearSearch(list,num):
    for i,val in enumerate(list):
    if (val == num):
    return True
    return False
    list = [5,8,4,6,9,2]
    num = 9
    if(LinearSearch(list,num)):
    print("Found")
    else:
    print("Not found")

  • @devendra1006
    @devendra1006 4 ปีที่แล้ว

    list=[3,4,6,78,5]
    n=3
    po=None
    def found(list,n):
    global po
    for i in range(len(list)):
    if list[i] == n:
    po=i
    return True
    else:
    return False
    if found(list,n):
    print('found at '+str(po))
    else:
    print('not found')

  • @afranmuzammil
    @afranmuzammil 6 ปีที่แล้ว

    pos = -1
    def search(l,n):
    for i in range(len(l)):
    if l[i]== n:
    globals()["pos"] = i
    return True
    return False
    l = [8,5,6,1,2,3]
    n = 5
    if search(l,n):
    print("found at ", pos+1)
    else:
    print("not found")

  • @govindtata
    @govindtata 4 ปีที่แล้ว

    n=int(input("Enter the no. of elements"))
    list=[]
    for i in range(n):
    x=int(input("Enter next value"))

    list.append(x)

    print(list)



    n=int(input("please enter the item to search"))
    def search(list,n):

    for j in range(len(list)):

    if list[j]==n:

    return True

    return False
    if search(list,n):

    print("ya, got it!")

    else:

    print("please enter correct element")

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

    n=int(input())
    arr=[]
    flag=0
    for i in range(0,n):
    ele=int(input())
    arr.append(ele)
    k=int(input())
    for i in range(0,n):
    if(k==arr[i]):
    flag=1
    if(flag==1):
    print("element found at",i+1)
    else:
    print("Element not found")

  • @GokkulG
    @GokkulG 6 หลายเดือนก่อน

    list=[2,8,7,9,6,4,3,5,1]
    n=int(input("please give the value between 1-9 : "))
    def search(list,n):
    for i in list:
    if list[i]!=n:
    pass
    elif list[i]==n:
    print("found at ",i+1)
    return True
    search(list,n)

  • @SantoshRaj-hx7rx
    @SantoshRaj-hx7rx 5 ปีที่แล้ว

    def search(list, n):
    for i in range(0, len(list)):
    if list[i] == n:
    return i
    return -1
    list = [1,3,5,7,9,0,6]
    n = 7
    result = search(list, n)
    if result != -1:
    print("Number found at ",result)
    else:
    print("Number not found")

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

    list=(3,6,7,5,45,7,9,26,4)
    def search(list):
    value=int(input("Enter the value you want to search from list"))
    index=-1
    for x in list:
    index += 1
    if x==value:
    print("value exist in list"," , INDEX VALUE =",index)
    break
    else:
    print("not found")
    search(list)

  • @vernanonix
    @vernanonix 4 ปีที่แล้ว

    Decided to avoid needing a global variable:
    def search(list,n):
    for i in list:
    if i==n:
    pos=list.index(i)
    return True, pos
    return False, False
    list = [5,8,4,6,9,2]
    n=9
    result, pos = search(list,n)
    if result:
    print("Found at position",pos+1)
    else:
    print("Not found")

  • @shashankgujarathi8390
    @shashankgujarathi8390 4 ปีที่แล้ว

    def find(lst,value):
    n = 0
    for i in lst:
    n = n + 1
    if i == num:
    print('Value found',n)
    break
    else:
    print('we didnt find any value')

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

    Im a CS Student Sir Thank you so very much for you videos it helps me a lot your the best u deserve a like and a subscribe :)

  • @balamuralikrishnabiyyapu2810
    @balamuralikrishnabiyyapu2810 4 ปีที่แล้ว

    def search(lit,n):
    for i in range(len(lit)):
    globals()['pos']=i
    if lit[i] == n:
    return True
    return False
    list=[1,3,4,5]
    n=4
    if search(list,n):
    print("i found that ",pos)
    else:
    print("i cant find that")
    n=4