Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to implement linear search and take input.

def linear_search(alist, key):
    """Return index of key in alist. Return -1 if key not present."""
    for i in range(len(alist)):
        if alist[i] == key:
            return i
    return -1
 
 
alist = input('Enter the list of numbers: ')
alist = alist.split()
alist = [int(x) for x in alist]
key = int(input('The number to search for: '))
 
index = linear_search(alist, key)
if index < 0:
    print('{} was not found.'.format(key))
else:
    print('{} was found at index {}.'.format(key, index))
Comment

PREVIOUS NEXT
Code Example
Python :: discord python tts 
Python :: variable in python 
Python :: what is module in python 
Python :: python look up how many rows in dataframe 
Python :: sqlalchemy filter between dates 
Python :: python tkinter projects 
Python :: generate secret key python 
Python :: kivy button disable 
Python :: flask decoding base 64 image 
Python :: matplotlib subplots 
Python :: python time sleep 
Python :: pretty size python 
Python :: extract email address using expression in django 
Python :: Simple dictionary in Python 
Python :: how to make exe from.py file 
Python :: python fill zeros left 
Python :: auto slug field django 
Python :: how to check substring in python 
Python :: pandas nan values in column 
Python :: django-sslserver 
Python :: Write a program that prints #pythoniscool, followed by a new line, in the standard output. Your program should be maximum 2 lines long You are not allowed to use print or eval or open or import sys in your file 
Python :: python see if a number is greater than other 
Python :: shell script to run python 
Python :: pandas xa0 
Python :: get last n in list python 
Python :: py foreach 
Python :: python get current class name 
Python :: python is dict 
Python :: How to Use Python all() Function to Check for Letters in a String using all function 
Python :: how to get any letter of a string python 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =