python - Can someone help me make my program case unsensitive? -


this code far, right case sensitive. tried making string lowercase (using .lower) without success. can help?

file=open("numbertext.txt","w") my_string= input("enter sentence.   ") splitted = my_string.split()  d = {} l=[] i,j in enumerate(splitted):     if j in d:         l.append(d[j])     else:         d[j]=i         l.append(i) print(l)  file.write(str(l))  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 11, 5, 6]  file=open("newfile.txt","w")  file.close 

the function lower returns converted string , doesn't convert string self. should use lower here:

splitted = my_string.lower().split() 

optimization code:

d = {} l=[] i,j in enumerate(splitted):     l.append(d.setdefault(j, i))   open("numbertext.txt","w") f:     f.write(str(l)) 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -