Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

frequency of occurrence of that element in the list and the positions

#search for the occurrence of an element ina list using linear search. Find the
#frequency ofoccurrence of that element in the list and thepositions
________________________________________________________________________________
a=eval(input('Enter the list of number:'))
b=int(input('Enter the element to be searched :'))
index=[]
count=0
for i in range(len(a)):
 if a[i]==b:
  count+=1
  index.append(i)
print(b,'found',count,'times')
print(b,'is present at positions',index)
________________________________________________________________________________
#output:
--------------------------------------------------------------------------------
Enter the list of number:[7,1,5,7,9,66,1,4]
Enter the element to be searched :7
7 found 2 times
7 is present at positions [0, 3]
--------------------------------------------------------------------------------
 
PREVIOUS NEXT
Tagged: #frequency #occurrence #element #list #positions
ADD COMMENT
Topic
Name
5+8 =