CommencerCommencer gratuitement

Readability of various publications

In this exercise, you have been given excerpts of articles from four publications. Your task is to compute the readability of these excerpts using the Gunning fog score and consequently, determine the relative difficulty of reading these publications.

The excerpts are available as the following strings:

  • forbes- An excerpt from an article from Forbes magazine on the Chinese social credit score system.
  • harvard_law- An excerpt from a book review published in Harvard Law Review.
  • r_digest- An excerpt from a Reader's Digest article on flight turbulence.
  • time_kids - An excerpt from an article on the ill effects of salt consumption published in TIME for Kids.

Cet exercice fait partie du cours

Feature Engineering for NLP in Python

Afficher le cours

Instructions

  • Import the Readability class from readability.
  • Compute the gf object for each excerpt using the gunning_fog() method on Readability.
  • Compute the Gunning fog score using the the score attribute.
  • Print the list of Gunning fog scores.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import Readability
from readability import Readability

# List of excerpts
excerpts = [forbes, harvard_law, r_digest, time_kids]

# Loop through excerpts and compute gunning fog index
gunning_fog_scores = []
for excerpt in excerpts:
  gf = Readability(excerpt).____()
  gf_score = gf.____
  gunning_fog_scores.append(gf_score)
  
# Print the gunning fog indices
print(gunning_fog_scores)
Modifier et exécuter le code