{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Write a Python program to count the occurrences of each word in a given sentence\n", "\n", "def word_count(str):\n", " counts = dict()\n", " words = str.split()\n", "\n", " for word in words:\n", " if word in counts:\n", " counts[word] += 1\n", " else:\n", " counts[word] = 1\n", "\n", " return counts\n", "\n", "print( word_count('the quick brown fox jumps over the lazy dog.'))" ] } ], "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }