def linear_search(myList, x): for i in range(len(myList)): if myList[i] == x: return i return -1 myList = [1,3,4,6,7,8,10,12,23,45,56,78,99] x = 7 print(linear_search(myList, x))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter