This is my solution

A possible solution:

#Write your function here
def reversed_list(lst1, lst2):
  lst3 = []
  for n in lst2:
    lst3.insert(0, n)
  print(lst1, lst2, lst3)
  if lst1 == lst3:
    return True
  else:
    return False
 
#Uncomment the lines below when your function is done
print(reversed_list([1, 2, 3], [3, 2, 1]))
print(reversed_list([1, 5, 3], [3, 2, 1]))
print(reversed_list([2, 7, 3, 1], [1, 3, 7, 2]))
print(reversed_list([2, 7, 3, 1], [1, 7, 3, 2]))

And this generates and checks automatically the pair of lists:

##########
#This imports the random module for the random list generator.
import random

##########
# Random list generator.
# Generates a list with 5 integer numbers, among 0 and 9.
# The variable "ctrl" controls the while loop condition.
# You can generate larger lists changing the while loop condition.
def random_list_generator():
  ctrl = 0
  lst = []
  while ctrl != 5:
    ctrl += 1
    lst.append(random.randint(0, 9))
  return lst

##########
# Checks if "lst2" is the reversed version of "lst1".
# Generates a specular list of "lst2" called "lst3", and cheks if "lst1" (...)
# (...) and "lst" are equal.
# Returns "True" or "False".
def reversed_list(lst1, lst2):
  lst3 = []
  for n in lst2:
    lst3.insert(0, n)
  if lst1 == lst3:
    return True
  else:
    return False

##########
# Variable "x" controls the main while loop.
# Variable "iterations" permits both while loop control and information (...)
# (...) about how many iterations need the while loop to find a positive (...)
# (...) result (= "True").
# The results will be printed if there is a positive match.
# The iterations are caped at 1.000.000 for avoid infinite loops.
x = 1
iterations = 0

while x == 1 and (iterations <= 10**6):
    random_list1 = random_list_generator()
    random_list2 = random_list_generator()
    if reversed_list(random_list1, random_list2) == False:
        iterations += 1
    else:
        iterations += 1
        x = 0
        print(reversed_list(random_list1, random_list2),
              random_list1, random_list2, iterations)

A post was merged into an existing topic: Sharing solutions