# To reverse a list use simply: reverse() method
# Example
list = [1, 2, 3]
list.reverse()
# Output
[3, 2, 1]
# to reverse any other type, we can use reversed()
# The reversed() function returns an iterator that accesses the given sequence in the reverse order.
# Example
list = [1, 2, 3]
list(reversed(list))
# Output
[3, 2, 1]
# reversed() returns an iterator so we can loop over it
# Example
for num in reversed(list):
print(num)
# Output
3
2
1
#reversed() is used to reverse the order of elements of a str or a container
#you can't reverse a string and convert it back to a string using str()
a='redrum' ; b='ypareht deen I'
x=list(reversed(a))
y=list(reversed(b))
print(x) #yeilds ['m','u','r','d','e','r']
print(y) #yeilds['I',' ','n','e','e','d',' ','t','h','e','r','a','p','y']
#if we want a string version of the list, we can use the .join function
c=''.join(x) ; d=''.join(y)
print(c) #yeilds: murder
print(d) #yeilds: I need therapy
# To reverse a list use simply: reverse() method
# Example
list = [1, 2, 3]
list.reverse()
# Output
[3, 2, 1]
# to reverse any other type, we can use reversed()
# The reversed() function returns an iterator that accesses the given sequence in the reverse order.
# Example
list = [1, 2, 3]
list(reversed(list))
# Output
[3, 2, 1]
# reversed() returns an iterator so we can loop over it
# Example
for num in reversed(list):
print(num)
# Output
3
2
1
#reversed() is used to reverse the order of elements of a str or a container
#you can't reverse a string and convert it back to a string using str()
a='redrum' ; b='ypareht deen I'
x=list(reversed(a))
y=list(reversed(b))
print(x) #yeilds ['m','u','r','d','e','r']
print(y) #yeilds['I',' ','n','e','e','d',' ','t','h','e','r','a','p','y']
#if we want a string version of the list, we can use the .join function
c=''.join(x) ; d=''.join(y)
print(c) #yeilds: murder
print(d) #yeilds: I need therapy