I'm trying to figure out why this logic is only detecting any lowercase instance of "ghandi" in the string. Ideally, this logic should check the string for the word "ghandi" regardless of case and change the position of h, taking into account its case from the 2nd character to the 5th character. string msg should be any string containing "ghandi". This is for an irc bot.
msgList = msg.split()
for i in range(0, (len(msgList))):
if 'ghandi' in msgList[i].lower():
pos = i
g = list(msgList[i])
break
i = i - 1
if "h" in msgList[pos]:
h = "h"
else:
h = "H"
del g[1]
g.insert( 4, h)
g = ''.join(g)
del msgList[pos]
msgList.insert( 5, g )
msg = ' '.join(msgList)
cardinal.sendMsg(channel, msg)
You should do it as:
msgList = msg.split()
msgList = [i.lower() for i in msgList]
for i in range(0, (len(msgList))):
if 'ghandi' in msgList[i]:
...