So I'm trying to make a code that gets every word in a list and adds the same word with the first letter in lowercase or uppercase (depending on the word)
here's the code
lost = ["de", "da", "do"] #The actual list is much bigger and with numbers but this list is small and has the same problem
for x in lost:
if x[:1] == x[:1].lower():
try:
print x
int(x[:1])
except ValueError:
print x
lost.append(x[:1].upper() + x[1:])
elif x[:1] == x[:1].upper():
try:
int(x[:1])
except ValueError:
lost.append(x[:1].lower() + x[1:])
but after it did all the 3 words the for loop starts over again so the console looks like this:
de
de
da
da
do
do
de
de
da
da
do
do
....
why doesnt it stop after it has done those 3 words?
you are increasing the size of your list over and over again so you are cycling your initial list, again and again, to solve the issue you should store the "lost" values in a different list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With