Python | Convert case of elements in a list of strings
Given a list of strings, write a Python program to convert all 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 : Convert Uppercase to Lowercase using map
function
# Python code to convert all string # from uppercase to lowercase. # Using map function out = map ( lambda x:x.lower(), [ 'GeEk' , 'FOR' , 'gEEKS' ]) # Converting it into list output = list (out) # printing output print (output) |
chevron_right
filter_none
Output:
['geek', 'for', 'geeks']
Method #2: Convert Lowercase to Uppercase using List comprehension
# Python code to convert all string # from uppercase to lowercase. # Initialisation input = [ 'fun' , 'Foo' , 'BaR' ] # Converting lst = [x.upper() for x in input ] # printing output print (lst) |
chevron_right
filter_none
Output:
['FUN', 'FOO', 'BAR']
Recommended Posts:
- Python | Ways to sort list of strings in case-insensitive manner
- Python program to convert camel case string to snake case
- Python | Convert list of tuples to list of strings
- Python | Convert list of strings to list of tuples
- Python | Convert List of lists to list of Strings
- Python | Convert list of strings to space separated string
- Python | Convert list elements to bi-tuples
- Python | Convert column to separate elements in list of lists
- Python | Split strings in list with same prefix in all elements
- Python | Convert list of strings and characters to list of characters
- Python | Convert mixed data types tuple list to string list
- Python | Remove empty strings from list of strings
- Python | Convert list of numerical string to list of Integers
- Python | Convert string List to Nested Character List
- Python | Convert list of string into sorted list of integer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.