I am trying to generate a list of tuples from openai's API which seemed to work fine at first and the output also looks good when I print it out. Still python doesn't recognize it as a list of tuples as when I am trying to access an index of the list, I am getting an exception: IndexError: string index out of range
This is what I got from Openai:
[ ("Question: When and where was Johann Wolfgang von Goethe born?", "Answer: Johann Wolfgang von Goethe was born on August 28, 1749 in Frankfurt am Main"), ("Question: What was Goethe's father's profession?", "Answer: Goethe's father was a lawyer"), ("Question: Who was Johann Wolfgang von Goethe's mentor?", "Answer: Johann Wolfgang von Goethe was mentored by Johann Gottfried Herder"), ("Question: Where did Goethe work as a minister?", "Answer: Goethe worked as a minister in Weimar"), ("Question: When did Goethe pass away?", "Answer: Goethe passed away on March 22, 1832 in Weimar"), ("Question: What role did literature play in Goethe's childhood?", "Answer: Literature played a significant role in Goethe's childhood, as he had access to an extensive library and began creating stories and theater plays at a young age"), ("Question: What was Goethe's father's profession, even though he did not practice it?", "Answer: Goethe's father was a lawyer, but did not practice law"), ("Question: How many siblings did Goethe have, and who was the only one to reach adulthood?", "Answer: Goethe had five siblings, and the only one to reach adulthood was his sister Cornelia"), ("Question: What was the financial situation of the Goethe family during Johann Wolfgang's childhood?", "Answer: The Goethe family lived comfortably from inherited wealth, and Goethe never experienced poverty"), ("name", "Johann Wolfgang von Goethe - Important Points Array")]I created a function that determines wether an input is a list of tuples and it also returns "returned_array is not a list of tuples"
def is_list_of_tuples(variable): if isinstance(variable, list): if all(isinstance(item, tuple) for item in variable): return True return Falseif is_list_of_tuples(returned_array): print("returned_array is a list of tuples.")else: print("returned_array is not a list of tuples.")