CommencerCommencer gratuitement

Detect language of a list of strings

Now you will detect the language of each item in a list. A list called sentences has been created for you and it contains 3 sentences, each in a different language. They have been randomly extracted from the product reviews dataset.

Cet exercice fait partie du cours

Sentiment Analysis in Python

Afficher le cours

Instructions

  • Iterate over the sentences in the list.
  • Detect the language of each sentence and append the detected language to the empty list languages.

Exercice interactif pratique

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

from langdetect import detect_langs

languages = []

# Loop over the sentences in the list and detect their language
for sentence in _____:
    languages.____(____(sentence))
    
print('The detected languages are: ', languages)
Modifier et exécuter le code