Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e254d9a

Browse files
Merge pull request fnplus#161 from SK7here/master
Linear search using Python
2 parents d157302 + 01a9b7c commit e254d9a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#Defining function for Linear Search
2+
def Linear_Search(input_list, key):
3+
flag = 0
4+
#Iterating each item in the list and comparing it with the key searching for
5+
for i in range(len(input_list)):
6+
if(input_list[i] == key):
7+
#If key matches with any of the list items
8+
flag = 1
9+
print("\nKey is found in the position: {}" .format(i))
10+
#If key not found
11+
if(flag == 0):
12+
print("\nKey not found")
13+
14+
#Input List
15+
input_list = [11,12,13,14,15,16,17,18,19]
16+
print("List available is {}" .format(input_list))
17+
#Getting Key from user
18+
key = input("\nEnter key to be searched in the list")
19+
key = int(key)
20+
#Calling function defined to perform Linear Search
21+
Linear_Search(input_list, key)
22+
23+
24+
25+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /