import feedparser

# URL of the BBC News RSS feed
rss_url = ‘http://feeds.bbci.co.uk/news/rss.xml’

# Parse the RSS feed
feed = feedparser.parse(rss_url)

# Create a dictionary to store news sources and their counts
news_sources = {}

# Loop through the feed entries and extract news sources
for entry in feed.entries:
source = entry.source.title if hasattr(entry, ‘source’) else ‘Unknown’
if source not in news_sources:
news_sources[source] = 1
else:
news_sources[source] += 1

# Print the news sources and their counts
for source, count in news_sources.items():
print(f”{source}: {count} headlines”)

# For graphical representation, you can use a library like Matplotlib
import matplotlib.pyplot as plt

# Extract data for plotting
sources = list(news_sources.keys())
counts = list(news_sources.values())

# Create a bar chart to represent news sources
plt.barh(sources, counts)
plt.xlabel(‘Number of Headlines’)
plt.title(‘News Sources in BBC News RSS Feed’)
plt.show()