Python | Convert case of elements in a list of strings
Given a list of strings, write a Python program to convert all strings from lowercase/uppercase to uppercase/lowercase.
Input : ['GeEk', 'FOR', 'gEEKS'] Output: ['geek', 'for', 'geeks'] Input : ['fun', 'Foo', 'BaR'] Output: ['FUN', 'FOO', 'BAR']
Method #1: Convert Uppercase to Lowercase using map function
Python3
# Python code to convert all string# from uppercase to lowercase.# Using map functionout = map(lambda x:x.lower(), ['GeEk', 'FOR', 'gEEKS'])# Converting it into listoutput = list(out)# printing outputprint(output) |
Output:
['geek', 'for', 'geeks']
Method #2: Convert Lowercase to Uppercase using List comprehension
Python3
# Python code to convert all string# from uppercase to lowercase.# Initialisationinput = ['fun', 'Foo', 'BaR']# Convertinglst = [x.upper() for x in input]# printing outputprint(lst) |
Output:
['FUN', 'FOO', 'BAR']
Method: Using enumerate function
Python3
lst = ['Foo', 'fOO', 'geeKs']lst = [i.lower() for a,i in enumerate(lst)]print(lst) |
Output
['foo', 'foo', 'geeks']





Please Login to comment...