Python Practice › List Programs › Program 61

Capitalise the first and last letters

EasyList Programs · 61 of 100

Write a Python program to make the first and last letters of each word uppercase, and also print every word in lowercase.

Advertisement
Input
["Learn", "python", "From", "Sqa", "tools"]
Output
['LearN', 'PythoN', 'FroM', 'SqA', 'ToolS']
['learn', 'python', 'from', 'sqa', 'tools']

Approach

  1. Upper-case the ends and keep the middle.

Solution

Python
words = ["Learn", "python", "From", "Sqa", "tools"]print([w[0].upper() + w[1:-1] + w[-1].upper() for w in words])print([w.lower() for w in words])
Output
['LearN', 'PythoN', 'FroM', 'SqA', 'ToolS']
['learn', 'python', 'from', 'sqa', 'tools']

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment