61. Problem to convert characters to Uppercase and lowercase in a list

In this Python list program, we will take a user input as a list and the first and last letter of each item from Uppercase and Lowercase with the help of the below-given steps.

Convert characters to Uppercase and lowercase in a list:

Steps to solve the program
  1. Take a list with words as input.
  2. Create two empty lists.
  3. Use a for loop to iterate over words in the list.
  4. Convert the first and last character of each word into an Uppercase and Lowercase character and add them to the corresponding empty lists using the upper() and lower() function and indexing.
  5. Print the lists to see the output.
				
					#Input list
list1 = ["Learn", "python", "From", "Sqa", "tools"]

#Creating empty lists
list2 = []
list3 = []
for words in list1:
    list2.append( words[0].upper()+words[1:-1]
                 + words[-1].upper() + " ")
#Printing output
print("Uppercase: ",list2)

for words in list1:
    list3.append( words[0].lower()+words[1:-1] 
                 + words[-1].lower() + " ")
#Printing output    
print("Lowercase: ",list3)
				
			

Output :

				
					Uppercase:  ['LearN ', 'PythoN ', 'FroM ', 'SqA ', 'ToolS ']
Lowercase:  ['learn ', 'python ', 'from ', 'sqa ', 'tools ']
				
			

Related Articles

Zip two lists of lists into a list

Maximum and minimum from the heterogeneous list

Leave a Comment