This forum is now read-only. Please use our new forums at discuss.codecademy.com.

1181 points
5109c6ecff4b156a6100155f_655806896
Submitted by
Carmen
almost 5 years ago

14/34: print paragraph text --why not paragraph[0]?

I'm a little confused about this line:

for paragraph in story['textWithHtml']['paragraph']:
    print paragraph['$text'] + "\n"

Why aren't we iterating over story['textWithHtml'][paragraph][0] since all the contents within the paragraph dictionary is encased in a list?

Thanks!


0 votes

permalink

Iterating through story['textWithHtml'][paragraph][0] would get the keys for the first paragraph. You want to iterate through all the paragraphs and extract the text.

If you look at the json object it may prove illuminating.

"paragraph": [
    {
        "num": "1", 
        "$text": "foo"
    }, 
    {
        "num": "2", 
        "$text": "bar"
    }, 
...
    {
        "num": "32", 
        "$text": "baz"
    }, 
]

880 points
Daee8e3bc962772d72da9afb240a685b?s=140&d=retro
Submitted by
Henry Baughman
almost 5 years ago