Python | Convert the case of items in a list of strings



Given a list of strings, write a Python program to convert the entire string from lowercase / uppercase to uppercase / lowercase.

  Input:  [`GeEk`,` FOR`, `gEEKS`]  Output:  [` geeks`, `for`,` geeks`]  Input:  [`fun`,` Foo`, `BaR`]  Output:  [`FUN`,` FOO`, `BAR`] 

Method # 1: Converting upper and lower case using the map function

# Python code to convert the entire line
# from uppercase to lowercase .

 
# Using the map function

out = map ( lambda x: x.lower (), [ `GeEk` , ` FOR` , `gEEKS` ])

 
# Convert it to a list

output = list (out)

 
# print output

print (output)

Output:

 [`geek`,` for`, `geeks`] 

Method # 2: Converting lowercase to uppercase using a list comprehension

# Python code for converting sun her lines
# from uppercase to lowercase.

 
# Initialization

input = [ `fun` , ` Foo ` , ` BaR` ]

 
# Conversion

lst = [x.upper () for x in input ]

 
# printout

print (lst) 

Exit:

 [`FUN `,` FOO`, `BAR`]