Skip to main content
deleted 1 character in body
Source Link
Penny Liu
  • 17.9k
  • 5
  • 89
  • 109

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:

def indexof( array, elem): try: return array.index(elem) except ValueError: return -1 

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:

def indexof( array, elem): try: return array.index(elem) except ValueError: return -1 

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:

def indexof(array, elem): try: return array.index(elem) except ValueError: return -1 
using the same logic to a usable function. search is not only for strings as it was ( 'search word')
Source Link

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:

def indexof( array, elem): try:   index =return array.index('search_keyword'elem) except ValueError:   index =return -1 

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 

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:

def indexof( array, elem): try: return array.index(elem) except ValueError: return -1 
deleted 30 characters in body
Source Link

Python index() method throws an error if the item was not found, which sucks!

. 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 

Python index() method throws an error if the item was not found, which sucks!

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 

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 
Active reading [<http://en.wikipedia.org/wiki/JavaScript>]
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
Source Link
Hamed Baatour
  • 7k
  • 3
  • 40
  • 49
Loading