def get_messages_count(conversations):
    totals = {}
    for conv in conversations:
        totals.setdefault(conv.conversation_type, {})
        totals[conv.conversation_type].setdefault('sent', 0)
        totals[conv.conversation_type].setdefault('received', 0)
        totals[conv.conversation_type]['sent'] += conv.count_sent_messages()
        totals[conv.conversation_type]['received'] += conv.count_replies()
    return totals
def get_messages_count(conversations):
    totals = {}
    for conv in conversations:
        totals.setdefault(conv.conversation_type, {})
        totals[conv.conversation_type].setdefault('sent', 0)
        totals[conv.conversation_type].setdefault('received', 0)
        totals[conv.conversation_type]['sent'] += conv.count_sent_messages()
        totals[conv.conversation_type]['received'] += conv.count_replies()
    return totals