hice un código para cambiar mayúsculas por minúsculas y viceversa. Tengo un problema, el input:
input: hola como estan
pero el output:
output: HOLA COMo ESTAN
La o en "como" no se vio afectada por el código:
import re
def convert(w):
return list(filter(None, re.split('\W+', w)))
def lol(w):
a1 = (
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z"])
a2 = (
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z"])
w_list = list(map(str, w))
w_listf = list(map(str, w))
for i in w_list:
if i in a1:
index = a1.index(i)
indexs = w_list.index(i)
w_pos = a2[index]
w_listf[indexs] = w_pos
elif i in a2:
index2 = a2.index(i)
indexs2 = w_list.index(i)
w_pos2 = a1[index2]
w_listf[indexs2] = w_pos2
r = str("".join(w_listf))
return r
a = input()
ac = convert(a)
for i in ac:
print(lol(i))
str.index()
te da solo el índice de la primera aparición. Si la letra aparece varias veces, tu enfoque sólo cambia la primera. Por otro lado ¿es un ejercicio o es una necesidad real? Porque si es una necesidad, Python ya te lo da hecho:a.upper()