# more-lists.py # A set of functions for demonstrating different operations on lists. def list_to_string(some_list): """ Creates a string from a list :param some_list: (list) the list to turn into a string :return: (str) a string where all elements of the list have been appended to """ result = "" for val in some_list: result = result + str(val) + " " # skip the last " " return result[0:-1] def string_to_list(some_string): """ Creates a list from a string :param some_string: (str) the string to turn into a list :return: (list) a list where each index corresponds to a character from the original string """ result = [] for char in some_string: result.append(char) return result def multiply_lists(list1, list2): """ Creates a new list that is the result of the multiplication of two equally-lengthed lists of numbers :param list1: (list) the first list of numbers :param list2: (list) the second list of numbers :return: (list) a list where each index corresponds to the multiplication of the numbers existing in the same index in list1 and list2 """ result = [] if len(list1) != len(list2): print("Error: lists are not of equal length!") else: for i in range(len(list1)): result.append(list1[i] * list2[i]) return result