new_articles = {
“article_1”:“On Independence Day eve, President Murmu calls on tribals to embrace modernity”,
“article_2”:“President approves Tatrakshak Medals for Indian Coast Guard personnel | List”,
“article_3”:“Pushed by food prices, retail inflation leaps to 7.4%, a 15-month high”,
“article_4”:“Shatrughan Sinha pitches Mamata Banerjee as PM face for 2024 elections”
}
From the above dictionary populate a summary dictionary for each article as key and its summary statistics as values
Sample output:
new_articles = {
“article_1”: “On Independence Day eve, President Murmu calls on tribals to embrace modernity”,
“article_2”: “President approves Tatrakshak Medals for Indian Coast Guard personnel | List”,
“article_3”: “Pushed by food prices, retail inflation leaps to 7.4%, a 15-month high”,
“article_4”: “Shatrughan Sinha pitches Mamata Banerjee as PM face for 2024 elections”
}
summary_dict = {}
for key, article in new_articles.items():
words = article.split()
word_count = len(words)
num_capital_words = sum(1 for word in words if word[0].isupper())
num_unique_characters = len(set(article))
new_dict={}
for key,value in new_articles.items():
value_dict={}
x=new_articles[key].split(" ")
#print(x)
size=len(x)
count=0
for i in x:
if i[0].isupper():
count+=1
x=set(x)
size2=len(x)
value_dict['word_count']=size
value_dict['num_of_words_which_start_with_capital']=count
value_dict['num_of_unique_character']=size2
new_dict[key]=key
new_dict[key]=value_dict
print(new_dict)
import json
with open('student_data.json','w') as file_handler:
file_handler.write(json.dumps(new_dict))
new_articles = {
“article_1”:“On Independence Day eve, President Murmu calls on tribals to embrace modernity”,
“article_2”:“President approves Tatrakshak Medals for Indian Coast Guard personnel | List”,
“article_3”:“Pushed by food prices, retail inflation leaps to 7.4%, a 15-month high”,
“article_4”:“Shatrughan Sinha pitches Mamata Banerjee as PM face for 2024 elections”
}
summary_dict={}
for key,value in new_articles.items():
word=value.split( )
word_count=len(word)
upper=[word for word in word if word[0].isupper()]
num_of_unique_characters=len(set(value))
summary_dict[key]={“word_count”:word_count,
“num_of_words_which_start_with_capital”:upper,
“num_of_unique_character”:num_of_unique_characters}
print(summary_dict)
import json
with open(“news_article_summary.json”,“w”)as file_handler:
file_handler.write(json.dumps(summary_dict))
import json
new_articles = {
"article_1": "On Independence Day eve, President Murmu calls on tribals to embrace modernity",
"article_2": "President approves Tatrakshak Medals for Indian Coast Guard personnel | List",
"article_3": "Pushed by food prices, retail inflation leaps to 7.4%, a 15-month high",
"article_4": "Shatrughan Sinha pitches Mamata Banerjee as PM face for 2024 elections"
}
summary_dict = {}
for a_name, a_text in new_articles.items():
words = a_text.split()
word_count = len(words)
num_of_words_start_with_capital = sum(1 for word in words if word[0].isupper())
num_of_unique_characters = len(set(a_text))
summary_dict[a_name] = {
"word_count": word_count,
"start_with_capital": num_of_words_start_with_capital,
"unique_characters": num_of_unique_characters
}
with open("news_article_summary.json", "w") as file_h:
file_h.write(json.dumps(summary_dict))
print("Summary dictionary has been written to news_article_summary.json")