Reverse All Strings in String List in Python
Last Updated :
03 May, 2025
We are given a list of strings and our task is to reverse each string in the list while keeping the order of the list itself unchanged. For example, if we have a list like this: ['gfg', 'is', 'best'] then the output will be ['gfg', 'si', 'tseb'].
Using For Loop
We can use a for loop to iterate over the list and reverse each string. This method is easy to understand and very readable.
Python
a = ["apple", "banana", "cherry", "date"]
res = []
for s in a:
res.append(s[::-1])
print(res)
Output['elppa', 'ananab', 'yrrehc', 'etad']
Explanation: We iterate over each string s in list a and reverse it using slicing (s[::-1]), then append the reversed string to res list.
Using List comprehension
List comprehension is a concise and efficient way to reverse all strings in a list. It allows us to iterate over the list and apply a transformation to each element.
Python
a = ["apple", "banana", "cherry", "date"]
res = [s[::-1] for s in a]
print(res)
Output['elppa', 'ananab', 'yrrehc', 'etad']
Explanation: list comprehension iterates over each string in a and for each string s[::-1] reverses each string.
Using map() Function
map() function provides a way to applying a function to all elements of an iterable. In this case, we can use map() with a lambda function to reverse each string.
Python
a = ["apple", "banana", "cherry", "date"]
res = list(map(lambda s: s[::-1], a))
print(res)
Output['elppa', 'ananab', 'yrrehc', 'etad']
Explanation:
- map() function applies lambda function lambda s: s[::-1] to each string in the list a.
- lambda s: s[::-1] reverses each string.
- list() function is used to convert the result from a map object into a list.
Reverse Strings Without String Slicing
This method avoids string slicing and instead uses string concatenation to reverse each string in the list. It’s a straightforward way to manually reverse strings using loops
Python
a = ["apple", "banana", "cherry", "date"]
for i in range(len(a)):
temp = ''
for ch in a[i]:
temp = ch + temp
a[i] = temp
print(a)
Output['elppa', 'ananab', 'yrrehc', 'etad']
Explanation:
- We iterate over each string in the list strings.
- For each string, we build its reverse by prepending each character to an empty string temp.
- The reversed string replaces the original string in the list.
Related Articles:
Similar Reads
How To Reverse A List In Python Using Slicing In Python, list slicing is a common practice and it is the most used technique for programmers to solve efficient problems. In this article, we will see how we can reverse a list using slicing in Python. Reverse a List Using Slicing in PythonBelow are some of the examples by which we can perform rev
3 min read
Python - Reverse Slicing of given string Reverse slicing in Python is a way to access string elements in reverse order using negative steps.Using Slicing ([::-1])Using slicing with [::-1] in Python, we can reverse a string or list. This technique works by specifying a step of -1, which starts at the end of the sequence and moves backward,
1 min read
Python | Reverse Incremental String Slicing Sometimes, while working with Python strings, we can have a problem in which we need to perform the slice and print of strings in reverse order. This can have applications in day-day programming. Let us discuss certain ways in which this task can be performed. Method #1: Using loops This is the brut
4 min read
Python - Reverse Range in String List Given a string list, reverse each element of string list from ith to jth index. Input : test_list = ["Geeksforgeeks", "Best", "Geeks"], i, j = 1, 2 Output : ['ee', 'es', 'ee'] Explanation : Range of strings are extracted. Input : test_list = ["Geeksforgeeks"], i, j = 1, 7 Output : ['eeksfor'] Explan
3 min read
Python | Reverse Interval Slicing String Sometimes, while working with strings, we can have a problem in which we need to perform string slicing. In this, we can have a variant in which we need to perform reverse slicing that too interval. This kind of application can come in day-day programming. Let us discuss certain ways in which this t
4 min read