Searching and Sorting
Searching and Sorting
[ ]: list1=[4,2,7,5,12,54,21,64,12,32]
x=int(input("Please enter a number to search for : "))
for i in list1:
if x==i:
print("We have found",x,"and it is located at index number",list1.
↪index(i))
[ ]: list1 = [4,2,7,5,12,54,21,64,12,2,32]
x=int(input("Please enter a number to search for : "))
for idx, i in enumerate(list1):
if x==i:
print("We have found",x,"and it is located at index number",idx)
# If the element is present at the middle index, return the index as␣
↪the answer.
if array[mid] == E:
return mid
1
# As the element is not present in the array, return -1.
else:
return -1
if __name__ == "__main__":
array = [13, 110, 115, 120, 135, 140, 260]
E = 115
low = 0
high = len(array) - 1
if index != -1:
print(f"Element {E} is found in the array at index", str(index))
else:
print(f"Element {E} is not present in the array.")
[ ]: l=[10,20]
str(l[0])
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]: