Python | Return lowercase characters from given string

Sometimes, while working with strings, we are concerned about the case-sensitivity of strings and might require to get just a specific case of character in a long string. Let’s discuss certain ways in which only lowercase letters can be extracted from a string.

Method #1 : Using list comprehension + islower()
List comprehension and islower function can be used to perform this particular task. The list comprehension is primarily used to iterate over the list and islower function checks for the lowercase characters.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Return lowercase characters in string 
# Using list comprehension + islower()
  
# initializing string 
test_str = "GeeksForGeeKs"
  
# printing original string 
print("The original string is : " + str(test_str))
  
# Return lowercase characters in string 
# Using list comprehension + islower()
res = [char for char in test_str if char.islower()]
  
# printing result 
print("The lowercase characters in string are : " + str(res))

chevron_right


Output :



The original string is : GeeksForGeeKs
The lowercase characters in string are : [‘e’, ‘e’, ‘k’, ‘s’, ‘o’, ‘r’, ‘e’, ‘e’, ‘s’]

 

Method #2 : Using filter() + lambda
Filter function along with lambda functionality can be used to perform this particular task. The filter function performs the specific selection of case characters and lambda function is used for string traversal.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Return lowercase characters in string 
# Using filter() + lambda
  
# initializing string 
test_str = "GeeksForGeeKs"
  
# printing original string 
print("The original string is : " + str(test_str))
  
# Return lowercase characters in string 
# Using filter() + lambda
res = list(filter(lambda c: c.islower(), test_str))
  
# printing result 
print("The lowercase characters in string are : " + str(res))

chevron_right


Output :

The original string is : GeeksForGeeKs
The lowercase characters in string are : [‘e’, ‘e’, ‘k’, ‘s’, ‘o’, ‘r’, ‘e’, ‘e’, ‘s’]



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.