I am new to python and I am encountering this issue.
I have api witch fetches word definition.
this is the code:
import requests
def get_random_word_definition():
definition_api_url = 'https://api.dictionaryapi.dev/api/v2/entries/en/hello'
definition_api_url_response = requests.get(definition_api_url)
return definition_api_url_response.text
print(get_random_word_definition())
This is the output:
[{"word":"hello","phonetic":"həˈləʊ","phonetics":[{"text":"həˈləʊ","audio":"//ssl.gstatic.com/dictionary/static/sounds/20200429/hello--_gb_1.mp3"},{"text":"hɛˈləʊ"}],"origin":"early 19th century: variant of earlier hollo ; related to holla.","meanings":[{"partOfSpeech":"exclamation","definitions":[{"definition":"used as a greeting or to begin a phone conversation.","example":"hello there, Katie!","synonyms":[],"antonyms":[]}]},{"partOfSpeech":"noun","definitions":[{"definition":"an utterance of ‘hello’; a greeting.","example":"she was getting polite nods and hellos from people","synonyms":[],"antonyms":[]}]},{"partOfSpeech":"verb","definitions":[{"definition":"say or shout ‘hello’.","example":"I pressed the phone button and helloed","synonyms":[],"antonyms":[]}]}]}]
I want to get definition from the result and so far I've tried getting dictionary this way:
print(get_random_word_definition()[0])
But the output for this was : [.
I've also tried:
print(get_random_word_definition()['definitions'])
But output was error saying that I should index instead of string
Any suggestions please?