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
- Take a list with words as input.
- Create two empty lists.
- Use a for loop to iterate over words in the list.
- 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.
- 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
Python to find maximum and minimum values in the given heterogeneous list.
Python program to sort a given list in ascending order according to the sum of its sublist.
Python program to extract the specified sizes of strings from a given list of string values.
Python program to find the difference between consecutive numbers in a given list.
Python program to calculate the average of the given list.
Python program to count integers in a given mixed list.