{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import collections" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the names, splitting the lines into individual names." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "200" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "invites = [line.strip().split(', ') for line in open('../../data/00-invites.txt')]\n", "len(invites)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Find the line with most names" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "33" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "max(len(invite) for invite in invites)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a `Counter` from the flattended list of list of names. Then count how many items are in the `Counter` with a count of more than 1." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "457" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "invite_counts = collections.Counter(name for invite in invites for name in invite)\n", "sum(1 for name in invite_counts if invite_counts[name] > 1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }