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
Post a Comment