For Bite 4, this is the first time I've tried to use ElementTree so I am getting a little stuck on getting a proper count. I assume the issue is with how I am assigning categories.
def get_pybites_top_tags(n=5):
tree = ET.parse(tempfile)
root = tree.getroot()
categories = [category.text for category in root.iter('category')]
category_count = Counter(categories)
top_tags = category_count.most_common(n)
print (top_tags)
I can get the right count using BeautifulSoup except PyBites rejects using BS4 :( and I'd need to work on properly formatting the output.
soup = BeautifulSoup(content, 'lxml')
def get_pybites_top_tags(n):
categories = soup.find_all('category')
category_count = Counter([category.text for category in categories])
top_tags = category_count.most_common(n)
tag_list = [f"({tag}: {count})" for tag, count in top_tags]
return tag_list
print(get_pybites_top_tags(5))
So I think I have two challenges:
Getting the right count
Formatting the list such that it returns looking like:
For Bite 4, this is the first time I've tried to use
ElementTree
so I am getting a little stuck on getting a proper count. I assume the issue is with how I am assigningcategories
.I can get the right count using BeautifulSoup except PyBites rejects using BS4
:(
and I'd need to work on properly formatting the output.So I think I have two challenges:
Whereas I'm getting: