Split gives an index out of range error

Does this code in the inferring section work correctly? I am getting an index out of range error.

topic_dict = {i.split(‘: ‘)[0]: int(i.split(’: ‘)[1]) for i in response.split(sep=’\n’)}
if topic_dict[‘nasa’] == 1:
print(“ALERT: New NASA story!”)

Appreciate the help.

The result of the previous exercise now comes in a different format compared to the video. The error disappears as soon as format is corrected by slightly modifying the prompt.

I´m getting the same error, did you fix it?

Hi @vkbalasub

In your code, the if statement will only be executed if the topic_dict dictionary contains an entry for the key “nasa” and the value of this entry is 1. However, the answer string does not contain a line beginning with the text nasa : 1. This means that the topic_dict dictionary does not contain an entry for the key “nasa”.

To solve this problem, consider checking the answer string for a line beginning with the text nasa :

I just solve the format of answer by
prompt = f"“”
Determine whether each item in the following list of
topics is a topic in the text below, which
is delimited with triple backticks.

Give your answer as jsonwith topic list items an key.
Give your answer for each topic 0 or 1 as value.\

List of topics: {", ".join(topic_list)}

Text sample: ‘’‘{story}’‘’
response = get_completion(prompt)