{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Methods\n", "\n", "- string, list, & dictionary\n", "- in place vs not in place\n", "- relationship to functions" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "#### Clicker Question #1\n", "\n", "What will the following code snippet print?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def my_func(my_dictionary):\n", " \n", " output = []\n", "\n", " for item in my_dictionary:\n", " value = my_dictionary[item]\n", " output.append(value) #append method adds an item to end of a list\n", " \n", " return output\n", "\n", "# create dictionary and execute function\n", "dictionary = {'first' : 1, 'second' : 2, 'third' : 3}\n", "out = my_func(dictionary)\n", "\n", "print(out)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "- A) ['first', 'second', 'third'] \n", "- B) {1, 2, 3}\n", "- C) ['first', 1, 'second', 2, 'third', 3] \n", "- D) [1, 2, 3] \n", "- E) None" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "slide" } }, "source": [ "## Methods" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "