I have a list of substrings that I have to match in a string iteratively; if matching then perform the desired functionality.
The problem is that, whenever I tried to access the list with loops it does not work. Otherwise if I hard code it then it works. I do not understand why it is so?
My code is here:
players_list = ['Circket', 'PSL', 'IPL', 't20', 'shahid afridi', 'aamer yamin']
length = len(players_list)
cur.execute("SELECT tweet FROM tweets_data") # Query for getting specific attribute
length = len(players_list)
for row in cur.fetchall():
i = 0
while (i<length):
#print players_list[i], 'tweet value', row
if players_list[i] in row:
print 'list item:', players_list[i]
print row
else:
print 'Else statement.'
i+=1
Output: it should display the rows only that match with the any of the substring value like:
substring is: cricket
row: Security officials concerned about cricket teams being named after militants