- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
- Find smallest element greater than K in Python
- Python – Average of digit greater than K
- Python – Filter Tuples Product greater than K
- Python - Consecutive Ranges of K greater than N
- Python - Number of values greater than K in list
- Python - Get the Index of first element greater than K
- Python – Extract dictionaries with values sum greater than K
- Python – Extract list with difference in extreme values greater than K
- Largest subarray having sum greater than k in C++
- Remove tuples from list of tuples if greater than n in Python
- Count subarrays with all elements greater than K in C++
- Count of alphabets having ASCII value less than and greater than k in C++
- Python - Find words greater than given length