Python index()
method throws an error if the item was not found. So instead you can make it similar to the indexOf()
function of JavaScript which returns -1
if the item was not found:
try:
index = array.index('search_keyword')
except ValueError:
index = -1