Given a string consisting of alphabets and others characters, remove all the characters other than alphabets and print the string so formed.
Input : str = "$Gee*k;s..fo, r'Ge^eks?" Output : GeeksforGeeks
This problem has existing solution please refer Remove all characters other than alphabets from string link.
We will solve this problem in python quickly using List Comprehension.
Approach : is
1. Traverse string 2. Select characters which lie in range of [a-z] or [A-Z] 3. Print them together
How does ord() and range() function works in python ?
- The ord() method returns an integer representing the Unicode code point of the given Unicode character.For example,
ord('5') = 53 and ord('A') = 65 and ord('$') = 36
- The range(a,b,step) function generates a list of elements which ranges from a inclusive to b exclusive with increment/decrement of given step.
- Python | Remove all values from a list present in other list
- Python List Comprehension | Segregate 0's and 1's in an array list
- Python | Convert list of strings and characters to list of characters
- Move all zeroes to end of array using List Comprehension in Python
- Python List Comprehension and Slicing
- K’th Non-repeating Character in Python using List Comprehension and OrderedDict
- Python List Comprehension | Sort even-placed elements in increasing and odd-placed in decreasing order
- Difference between List comprehension and Lambda in Python
- Python | Ways to initialize list with alphabets
- Count set bits using Python List comprehension
- Python List Comprehension to find pair with given sum from two arrays
- Python List Comprehension | Three way partitioning of an array around a given range
- Python | List comprehension vs * operator
- Python - Map vs List comprehension
- How to handle a Python Exception in a List Comprehension?
- Python | Remove trailing/leading special characters from strings list
- Python - Remove front K characters from each string in String List
- Python - Remove Rear K characters from String List
- Python - Remove words containing list characters
- Python | Remove elements of list that are repeated less than k times
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.