Open kif1205 opened 5 years ago
Python3 code to demonstrate
remove last character from list of strings
using list comprehension + list slicing
initializing list test_list = ['Manjeets', 'Akashs', 'Akshats', 'Nikhils']
printing original list
print("The original list : " + str(test_list))
using list comprehension + list slicing remove last character from list of strings
res = [sub[ : -1] for sub in test_list]
Python3 code to demonstrate remove last character from list of strings using map() + lambda
initializing list test_list = ['Manjeets', 'Akashs', 'Akshats', 'Nikhils']
printing original list
print("The original list : " + str(test_list))
using map() + lambda remove last character from list of strings
res = list(map(lambda i: i[ : -1], test_list))
https://www.geeksforgeeks.org/python-remove-last-character-in-list-of-strings/