Last Updated : 12 Jul, 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 LoopWe 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)
['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 comprehensionList 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)
['elppa', 'ananab', 'yrrehc', 'etad']
Explanation: list comprehension iterates over each string in a and for each string s[::-1] reverses each string.
Using map() Functionmap() 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)
['elppa', 'ananab', 'yrrehc', 'etad']
Explanation:
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)
['elppa', 'ananab', 'yrrehc', 'etad']
Explanation:
Related Articles:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4