Please am following a tutorial on http://www.saltycrane.com/blog/2008/06/django-blog-project-6-creating-standard/.The code creates tags and list them by their count. Below is the code am having problems with.
def create_tag_data(posts):
tag_data = []
count = {}
for post in posts:
tags = re.split(" ", post.tags)
for tag in tags:
if tag not in count:
count[tag] = 1
else:
count[tag] += 1
for tag, count in sorted(count.iteritems(), key=lambda(k, v): (v, k), reverse=True):
tag_data.append({'tag': tag,
'count': count,})
return tag_data
I don't understand this line
for tag, count in sorted(count.iteritems(), key=lambda(k, v): (v, k),reverse=True):
it tells me unpacking is not supported in python 3. Am using python 3. Please how do i write that particular line in python 3.
countin the first part of yourfor, since that is for your dictionary. So, maybefor tag, tag_count in ...