Searching a list for an integer. : List Indexing « List « Python






Searching a list for an integer.

 

# Create a list of even integers 0 to 198
aList = range( 0, 199, 2 )

secarhKey = int( raw_input( "Enter integer search key: " ) )

if secarhKey in aList:
   print "Found at index:", aList.index( secarhKey )
else:
   print "Value not found"

   
  








Related examples in the same category

1.List offset: start at zero, negative and slicingList offset: start at zero, negative and slicing
2.List value assignment and index referenceList value assignment and index reference
3.Negative List IndicesNegative List Indices
4.Change individual elements of a listChange individual elements of a list
5.Reference index in a list in Python.Reference index in a list in Python.
6.List: display one item through an indexList: display one item through an index