Bắt đầu ngayBắt đầu miễn phí

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.

Bài tập này là một phần của khóa học

Sentiment Analysis in Python

Xem khóa học

Hướng dẫn bài tập

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

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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)
Chỉnh sửa và Chạy Mã