Write Python3 code to demonstrate Remove Rear K characters from String List using list comprehension + list slicing
Topic: Write Python3 code to demonstrate Remove Rear K characters from String List using list comprehension + list slicing
Solution
test_list = ['Manjeets', 'Akashs', 'Akshats', 'Nikhils'] print("The original list : " + str(test_list)) K = 4 res = [sub[ : len(sub) - K] for sub in test_list] print("The list after removing last characters : " + str(res))
List all Python Programs