Django Code sample to create tags summary view for blog posts display

def create_tag_data(posts):
tag_data = []
count = {}
for post in posts:

    tags = re.split(",", post.tags.replace(" ",""))

    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