In this we are going to see a basic program to reverse a string using iterators in Python Programming Language.
class Rev:
def __init__(self, s):
self.s = s
self.l = len(self.s)
def __iter__(self):
self.c = 1
return self
def __next__(self):
if self.c <= self.l:
res = self.s[self.l-self.c]
self.c += 1
return res
else:
raise StopIteration
for i in Rev("Iterable"):
print(i, end="")
# Coded by Saahil
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP