Using python3:
- return the location of the first occurrence of value in list lst. Returns -1 if value is not in lst.
FindVal(lst, value)
- return a count of occurrence of value in list lst.
def FindVal(lst, value): index = -1 # Looping through each index for i in range(len(lst)): # Checking value at index i is value if(lst[i] == value): # seeing i to index index = i break # Returning index value return index # Testing print(FindVal([4,2,1,3,5], 1)) print(FindVal([4,2,1,3,1,5], 1)) print(FindVal([4,2,3,5], 1))
Get Answers For Free
Most questions answered within 1 hours.