I would suggest that you should convert your both string and the strings in stockdata
to uppercase in the search process so it'd be able to detect both Computer
and computer
You should also print sorry, not found
if no result was found and I've added a results
variable to see the search results.
def company(stockdata):
"""
searches for companies with the word inputted and gives back full
company names and ticker tags
"""
found = False
results = []
search = raw_input("search for: ")
word = search.upper()
for i in range(len(stockdata)):
if word in stockdata[i][0].upper() or word in stockdata[i][1].upper(): # I've used stockdata[i][0] because the string is in a list of list
found = True
results.append(stockdata[i][0])
if found:
print 'yes'
print 'results : ',results
else:
print "sorry, nothing found"
stock = [['AAME', 'Atlantic American Corporation', '2013-11-04', 4.04, 4.05, 4.01, 4.05, 5400.0, 4.05], ['AAON', 'AAON Inc.', '2013-11-04', 27.28, 27.48, 27.08, 27.32, 96300.0, 27.32], ['AAPL', 'Apple Inc.', '2013-11-04', 521.1, 526.82, 518.81, 526.75, 8716100.0, 526.75], ['AAWW', 'Atlas Air Worldwide Holdings', '2013-11-04', 38.65, 39.48, 38.65, 38.93, 490500.0, 38.93], ['AAXJ', 'iShares MSCI All Country Asia ex Japan Index Fund', '2013-11-04', 60.55, 60.55, 60.3, 60.48, 260300.0, 60.48], ['ABAX', 'ABAXIS Inc.', '2013-11-04', 36.01, 36.91, 35.89, 36.2, 208300.0, 36.2]]
company(stock)
produces: for the search term abaxis
yes
results : ['ABAX']
Note: please provide a sample of your stock data list which is passed onto the function if possible as to ensure this works