94. Problem to convert the character of each word to capital letter

In this Python list program, we will take a user input as a list and convert 3rd character of each word to the capital with the help of the below-given steps.

The character of each word to capital letter:

Steps to solve the program
  1. Take a list containing words as input.
  2. Use a for loop to iterate over words in the list.
  3. If the length of the word is greater than 3 then convert the 4th character of each word to capital using indexing and the upper() function.
  4. If not then add that word to the empty list.
  5. Add the new words to another list.
  6. Print the list to see the result.
				
					#Input list
list1 = ["Hello", "student", "are", "learning", 
         "Python", "Its", "Python", "Language"]
list2 = []
for value in list1:
    if len(value)>3:
        list2.append(value[:3]+value[3].upper()
                     +value[4:])
    else:
        list2.append(value)
        
#Printing output
print(list2)
				
			

Output :

				
					['HelLo', 'stuDent', 'are', 'leaRning', 'PytHon', 'Its', 'PytHon', 'LanGuage']
				
			

Related Articles

Replace ‘Java’ with ‘Python’ from the given list

Remove the 2nd character of each word from list

Leave a Comment