from bs4 import BeautifulSoup
import urllib2
# Imported libraries for future use.
response = urllib2.urlopen('http://www.nytimes.com').read()
soup = BeautifulSoup(response,"lxml")
host = []
#created empty list to append future words extracted from data set.
for story_heading in soup.find_all(class_="story-heading"):
story_title = story_heading.text.replace("\n", " ").strip()
new_story_title = story_title.encode('utf-8')
parts = new_story_title.split()[0]
i=['a','A','an','An','the','The','from','From','to','To','when','When','what','What','on','On','for','For']
if parts not in i:
host.append(parts)
else:
pass
#now i have to calculate the number of repeated words in the file and calcute the number of repeatation.
print host
作成したリストの繰り返し単語の数を計算する方法を教えてください。 実際には上記のコードについてもかなり混乱しています。 誰かが私が間違ったことを説明できるのであれば、それは感謝するでしょう。リスト内の単語を数えるには?
あなたが行うことができ、デフォルトで[カウンタ](https://docs.python.org/2/library/collections.html #collections.Counter) – r3ign
大文字と小文字は区別されますか? 「何」==「何」ですか、あるいはそれらを異なる値として扱うのでしょうか? –