I have a JSON file that has news headlines from different reporters and news sources. The contents of JSON file are shown below:
[{
"headline": "Weather is getting worse in Nepal",
"reporter": "XYZ",
"link": "bbc.com"
},
{
"headline": "Nepal launches its new Political Map",
"reporter": "Abc",
"link": "abc.com"
},
{
"headline": "Ten more people died of COVID-19 in India",
"reporter": "IND",
"link": "timesofindia.com"
},
{
"headline": "PM Oli health condition is better",
"reporter": "dfg",
"link": "ekantipur.com"
}
]
Now my goal here in this blog is to make a list of news headlines, reporters, and news sources such that I can run the further comparison as per my need. In order to do so, I used the JSON library in python. The source code is shown below:
import json
with open("news_headline.json", 'r') as f:
repo = json.load(f)
headlines = []
reporter = []
source = []
for item in repo:
headlines.append(item['headline'])
reporter.append((item['reporter']))
source.append(item['link'])
print("Headlines are: \n",headlines,
"\nThe reporters are: \n", reporter,
"\nThe news source are: \n", source)
The output of this code is shown below:
Headlines are:
['Weather is getting worse in Nepal', 'Nepal launches its new Political Map', 'Ten more people died of COVID-19 in India', 'PM Oli health condition is better']
The reporters are:
['XYZ', 'Abc', 'IND', 'dfg']
The news source are:
['bbc.com', 'abc.com', 'timesofindia.com', 'ekantipur.com']