- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Remove characters greater than K
When it is required to remove characters, which are greater than ‘K’, a simple iteration is used along with the ‘ord’ (Unicode representation) method.
Below is a demonstration of the same −
my_list = ["python", "is", "easy", "to", "learn"] print("The list is :") print(my_list) K = 9 print("The value of K is ") print(K) my_result =  for element in my_list: result_string = '' for sub in element: if (ord(sub) - 97 <= K): result_string += sub my_result.append(result_string) print("The resultant list is :") print(my_result)
The list is : ['python', 'is', 'easy', 'to', 'learn'] The value of K is 9 The resultant list is : ['h', 'i', 'ea', '', 'ea']
A list with strings is defined and is displayed on the console.
The value for K is defined and is displayed on the console.
An empty list is defined.
The list is iterated over, and an empty string is created.
The elements are checked to see if difference between Unicode representation of the element and 97 is less than K.
If yes, the element is appended to empty string.
Otherwise, this string is appended to the empty list.
This is displayed as output on the console.
- Python – Remove Tuples with difference greater than K
- Python Indices of numbers greater than K
- Python – Average of digit greater than K
- Python – Filter Tuples Product greater than K
- Find smallest element greater than K in Python
- Python - Consecutive Ranges of K greater than N
- Python - Number of values greater than K in list
- Python – Extract dictionaries with values sum greater than K
- Python - Get the Index of first element greater than K
- Python – Extract list with difference in extreme values greater than K
- Remove tuples from list of tuples if greater than n in Python
- Largest subarray having sum greater than k in C++
- Python program to print Rows where all its Elements’ frequency is greater than K
- List comprehension and ord() in Python to remove all characters other than alphabets
- Count subarrays with all elements greater than K in C++