{ "metadata": { "name": "", "signature": "sha256:ba058b35872fd1711452538c5ccbea9fee1779267f632947126e649413d42970" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "***\n", "# 5. \ub9ac\uc2a4\ud2b8\n", "***\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 01 \ub9ac\uc2a4\ud2b8\uc758 \uc77c\ubc18\uc5f0\uc0b0\n", "***\n", "- \ub9ac\uc2a4\ud2b8: \uc2dc\ud000\uc2a4 \uc790\ub8cc\ud615\uc774\uba74\uc11c \ubcc0\uacbd \uac00\ub2a5(Mutable)\n", "- \ub9ac\uc2a4\ud2b8\uc5d0\uc11c \uc9c0\uc6d0\ud558\ub294 \uc77c\ubc18\uc801\uc778 \uc5f0\uc0b0\n", " - \uc778\ub371\uc2f1, \uc2ac\ub77c\uc774\uc2f1, \uc5f0\uacb0, \ubc18\ubcf5, \uba64\ubc84\uc27d \ud14c\uc2a4\ud2b8" ] }, { "cell_type": "code", "collapsed": false, "input": [ "l = []\n", "l = [1,2,\"Great\"]\n", "print l[0], l[-1]\n", "print l[1:3], l[:]\n", "print\n", "\n", "L = range(10)\n", "print L[::2]\n", "print\n", "\n", "print l * 2\n", "print l + [3, 4, 5]\n", "print len(l)\n", "print\n", "print 4 in L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1 Great\n", "[2, 'Great'] [1, 2, 'Great']\n", "\n", "[0, 2, 4, 6, 8]\n", "\n", "[1, 2, 'Great', 1, 2, 'Great']\n", "[1, 2, 'Great', 3, 4, 5]\n", "3\n", "\n", "True\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Mutable \ud2b9\uc131\uc744 \uc9c0\ub2cc \ub9ac\uc2a4\ud2b8\uc758 \uac12 \ubcc0\uacbd" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = ['spam', 'eggs', 100, 1234]\n", "a[2] = a[2] + 23\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['spam', 'eggs', 123, 1234]\n" ] } ], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \uc6d0\uc18c\uc5d0 \ub300\ud55c \uc2ac\ub77c\uc774\uc2a4 \uce58\ud658" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = ['spam', 'eggs', 123, 1234]\n", "a[0:2] = [1,12] # \ub3d9\uc77c\ud55c \ud06c\uae30\uc5d0 \ub300\ud55c \uc2ac\ub77c\uc774\uc2a4 \uce58\ud658\n", "print a\n", "\n", "a[0:2] = [1] # \uc11c\ub85c \ub2e4\ub978 \ud06c\uae30\uc5d0 \ub300\ud55c \uc2ac\ub77c\uc774\uc2a4 \uce58\ud658\n", "print a\n", "\n", "a[0:1] = [1, 2, 3] # \uc11c\ub85c \ub2e4\ub978 \ud06c\uae30\uc5d0 \ub300\ud55c \uc2ac\ub77c\uc774\uc2a4 \uce58\ud658\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 12, 123, 1234]\n", "[1, 123, 1234]\n", "[1, 2, 3, 123, 1234]\n" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \uc6d0\uc18c\uc5d0 \ub300\ud55c \uc2ac\ub77c\uc774\uc2a4 \uc0ad\uc81c" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [1, 12, 123, 1234]\n", "a[0:2] = []\n", "\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[123, 1234]\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \uc6d0\uc18c \uc0ac\uc774\uc5d0 \uc2ac\ub77c\uc774\uc2a4 \uc0bd\uc785" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [123, 1234]\n", "a[1:1] = ['spam', 'ham'] # 1\ubc88\uc9f8 \uc778\ub371\uc2a4\uc5d0 \uc0bd\uc785\n", "print a\n", "\n", "b = [123, 1234] \n", "b[1:2] = ['spam', 'ham'] # 1\ubc88\uc9f8 \uc6d0\uc18c\uc5d0 \ub300\ud55c \uce58\ud658\n", "print b\n", "\n", "a[:0] = a # \ub9ac\uc2a4\ud2b8 \ub9e8 \uc55e\uc5d0 \uc790\uae30 \uc790\uc2e0\uc744 \uc0bd\uc785\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[123, 'spam', 'ham', 1234]\n", "[123, 'spam', 'ham']\n", "[123, 'spam', 'ham', 1234, 123, 'spam', 'ham', 1234]\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ud655\uc7a5 \uc2ac\ub77c\uc774\uc2a4\ub97c \uc0ac\uc6a9\ud558\ub294 \uacbd\uc6b0 \uc2ac\ub77c\uc774\uc2a4 \uce58\ud658\ub54c \uc694\uc18c\uc758 \uac1c\uc218\uac00 \uc77c\uce58\ud574\uc57c \ud568\n", "- [\ucc38\uace0] range \uc778\uc790 \ud574\uc11d\n", " - range(stop): \uc778\uc790\uac00 1\uac1c\uc778 \uacbd\uc6b0 start\ub294 0\uc774\uba70 \uc8fc\uc5b4\uc9c4 \uc778\uc790\ub294 stop(exclusive)\uc73c\ub85c \ud574\uc11d\n", " - range(start, stop): \uc778\uc790\uac00 2\uac1c\uc778 \uacbd\uc6b0 start(inclusive), stop(exclusive)\uc774\uace0, step\uc740 1\ub85c \ud574\uc11d\n", " - range(start, stop, step): \uc778\uc790\uac00 3\uac1c\uc778 \uacbd\uc6b0 \uac01\uac01\uc744 start(inclusive), stop(exclusive), step\uc73c\ub85c \ud574\uc11d" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = range(4)\n", "print a\n", "\n", "print a[::2]\n", "\n", "a[::2] = range(0, -2, -1) # a[0::2] = [0, 2], range(0, -2 -1) = [0, -1]\n", "print a\n", "\n", "a[::2] = range(3) # range(3) = [0, 1, 2], \ud655\uc7a5 \uc2ac\ub77c\uc774\uc2a4 \uc0ac\uc6a9\ud558\uc5ec \uce58\ud658\uc2dc\uc5d0\ub294 \ud06c\uae30\uac00 \ub2e4\ub97c \ub54c \uc5d0\ub7ec \ubc1c\uc0dd" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 2, 3]\n", "[0, 2]\n", "[0, 1, -1, 3]\n" ] }, { "ename": "ValueError", "evalue": "attempt to assign sequence of size 3 to extended slice of size 2", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# range(3) = [0, 1, 2], \ud655\uc7a5 \uc2ac\ub77c\uc774\uc2a4 \uc0ac\uc6a9\ud558\uc5ec \uce58\ud658\uc2dc\uc5d0\ub294 \ud06c\uae30\uac00 \ub2e4\ub97c \ub54c \uc5d0\ub7ec \ubc1c\uc0dd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: attempt to assign sequence of size 3 to extended slice of size 2" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- del\uc744 \uc774\uc6a9\ud55c \ub9ac\uc2a4\ud2b8 \uc694\uc18c \uc0ad\uc81c" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [1, 2, 3, 4]\n", "del a[0]\n", "print a\n", "\n", "del a[1:]\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[2, 3, 4]\n", "[2]\n" ] } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [ "a = range(4)\n", "print a\n", "print a[::2]\n", "\n", "del a[::2]\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 2, 3]\n", "[0, 2]\n", "[1, 3]\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "a = range(5)\n", "del a # \ub9ac\uc2a4\ud2b8 \uc790\uccb4\uc5d0 \ub300\ud55c \uc0ad\uc81c (\uc815\ud655\ud788\ub294 \ub9ac\uc2a4\ud2b8\ub97c \uac00\ub9ac\ud0a4\ub294 \ub808\ud37c\ub7f0\uc2a4\ub97c \uc9c0\ub2cc \ubcc0\uc218 a \uc0ad\uc81c)\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'a' is not defined", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0ma\u001b[0m \u001b[0;31m# \ub9ac\uc2a4\ud2b8 \uc790\uccb4\uc5d0 \ub300\ud55c \uc0ad\uc81c (\uc815\ud655\ud788\ub294 \ub9ac\uc2a4\ud2b8\ub97c \uac00\ub9ac\ud0a4\ub294 \ub808\ud37c\ub7f0\uc2a4\ub97c \uc9c0\ub2cc \ubcc0\uc218 a \uc0ad\uc81c)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined" ] } ], "prompt_number": 14 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 02 \uc911\ucca9 \ub9ac\uc2a4\ud2b8(nested lists)\n", "***\n", "- \uc911\ucca9 \ub9ac\uc2a4\ud2b8: \ub9ac\uc2a4\ud2b8 \uc548\uc5d0 \uc694\uc18c\ub85c\uc11c \ub9ac\uc2a4\ud2b8\ub97c \uc9c0\ub2cc \ub9ac\uc2a4\ud2b8" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = [1, 2, 3]\n", "t = ['begin', s, 'end']\n", "print t\n", "\n", "print t[1][1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['begin', [1, 2, 3], 'end']\n", "2\n" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "s[1] = 100\n", "print t" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['begin', [1, 100, 3], 'end']\n" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, ['a', ['x', 'y'], 'b'], 3]\n", "print L[0]\n", "print L[1]\n", "print L[1][1]\n", "print L[1][1][1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n", "['a', ['x', 'y'], 'b']\n", "['x', 'y']\n", "y\n" ] } ], "prompt_number": 22 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 03 \ub9ac\uc2a4\ud2b8\uc758 \uba54\uc3d8\ub4dc\ub4e4\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3-1 \ub9ac\uc2a4\ud2b8 \uba54\uc3d8\ub4dc" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = [1, 2, 3]\n", "\n", "s.append(5) # \ub9ac\uc2a4\ud2b8 \ub9e8 \ub9c8\uc9c0\ub9c9\uc5d0 \uc815\uc218 \uac12 5 \ucd94\uac00\n", "print s\n", "\n", "s.insert(3, 4) # 3 \uc778\ub371\uc2a4 \uc704\uce58\uc5d0 \uc815\uc218 \uac12 4 \ucd94\uac00\n", "print s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 2, 3, 5]\n", "[1, 2, 3, 4, 5]\n" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "s = [1, 2, 3, 4, 5]\n", "\n", "print s.index(3) # \uac12 3\uc758 \uc778\ub371\uc2a4 \ubc18\ud658\n", "\n", "print s.count(2) # \uac12 2\uc758 \uac1c\uc218 \ubc18\ud658\n", "\n", "s = [1, 2, 2, 2, 2, 2, 3, 4, 5]\n", "print s.count(2)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "2\n", "1\n", "5\n" ] } ], "prompt_number": 24 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- python\uc758 \uc18c\ud305 \uc54c\uace0\ub9ac\uc998: Timsort (\ubcc0\ud615\ub41c merge sort)\n", " - \ucc38\uace0: http://orchistro.tistory.com/175" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = [1, 2, -10, -7, 100]\n", "s.reverse() # \uc790\ub8cc\uc758 \uc21c\uc11c\ub97c \ub4a4\uc9d1\uae30 (\ubc18\ud658\uac12 \uc5c6\uc74c) \n", "print s\n", "\n", "s.sort() # \uc815\ub82c (\ubc18\ud658\uac12 \uc5c6\uc74c)\n", "print s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[100, -7, -10, 2, 1]\n", "[-10, -7, 1, 2, 100]\n" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "s = [10, 20, 30, 40, 50]\n", "s.remove(10) # \uc790\ub8cc \uac12 10 \uc0ad\uc81c\n", "print s\n", "\n", "s = [10, 20, 30, 20, 40, 50] # \uc790\ub8cc \uac12\uc774 \uc5ec\ub7ec\uac1c \uc874\uc7ac\ud558\uba74 \uccab\ubc88\uc9f8 \uac83\ub9cc \uc0ad\uc81c\n", "s.remove(20)\n", "print s\n", "\n", "s.extend([60, 70]) # \uc0c8\ub85c\uc6b4 \ub9ac\uc2a4\ud2b8([60, 70]\ub97c \uae30\uc874 \ub9ac\uc2a4\ud2b8 s \ub4a4\uc5d0 \ubcd1\ud569\n", "print s\n", "\n", "s.append([60, 70]) # \uc8fc\uc758: append\ub85c \uc0c8\ub85c\uc6b4 \ub9ac\uc2a4\ud2b8\ub97c \ucd94\uac00\ud558\uba74 \ud558\ub098\uc758 \uc790\ub8cc \uc694\uc18c\ub85c\uc11c \ucd94\uac00\n", "print s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[20, 30, 40, 50]\n", "[10, 30, 20, 40, 50]\n", "[10, 30, 20, 40, 50, 60, 70]\n", "[10, 30, 20, 40, 50, 60, 70, [60, 70]]\n" ] } ], "prompt_number": 36 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3-2 \ub9ac\uc2a4\ud2b8\ub97c \uc2a4\ud0dd(Stack)\uc73c\ub85c \uc4f0\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = [10, 20, 30, 40, 50]\n", "s.append(60)\n", "print s\n", "\n", "print s.pop()\n", "\n", "print s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[10, 20, 30, 40, 50, 60]\n", "60\n", "[10, 20, 30, 40, 50]\n" ] } ], "prompt_number": 37 }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](images/stack.png)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "s = [10, 20, 30, 40, 50]\n", "print s.pop(0) #0 \ubc88\uc9f8 \uc778\ub371\uc2a4 \uac12\uc744 \uaebc\ub0b8\ub2e4.\n", "\n", "print s\n", "\n", "print s.pop(1) #1 \ubc88\uc9f8 \uc778\ub371\uc2a4 \uac12\uc744 \uaebc\ub0b8\ub2e4.\n", "\n", "print s" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "10\n", "[20, 30, 40, 50]\n", "30\n", "[20, 40, 50]\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3-3 \ub9ac\uc2a4\ud2b8\ub97c \ud050(Queue)\ub85c \uc4f0\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "q = [10, 20, 30, 40, 50]\n", "q.append(60)\n", "print q.pop(0)\n", "\n", "print q" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "10\n", "[20, 30, 40, 50, 60]\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](images/queue.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 04 \ud29c\ud50c \ud639\uc740 \ub9ac\uc2a4\ud2b8\uc758 \ub9ac\uc2a4\ud2b8 \ubc18\ubcf5 \ucc38\uc870\ud558\uae30\n", "***\n", "- \ub9ac\uc2a4\ud2b8 \uc548\uc758 \uac01 \uc790\ub8cc\uac00 \ud29c\ud50c\uc77c \ub54c for \ubb38\uc744 \uc0ac\uc6a9\ud558\uc5ec \uac12 \ucd94\ucd9c \ubc29\ubc95" ] }, { "cell_type": "code", "collapsed": false, "input": [ "lt = [('one', 1), ('two', 2), ('three', 3)]\n", "for t in lt:\n", " print 'name =', t[0] ,', num =', t[1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "name = one , num = 1\n", "name = two , num = 2\n", "name = three , num = 3\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc544\ub798 \ucf54\ub4dc\uac00 \ub354 \ud6a8\uc728\uc801" ] }, { "cell_type": "code", "collapsed": false, "input": [ "lt = [('one', 1), ('two', 2), ('three', 3)]\n", "for t in lt:\n", " print 'name = %s, num = %s' % t" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "name = one, num = 1\n", "name = two, num = 2\n", "name = three, num = 3\n" ] } ], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- for \ubb38\uc758 \ud5e4\ub354\uc5d0\uc11c \uac01 \ud29c\ud50c\uc758 \uac12 \ucd94\ucd9c" ] }, { "cell_type": "code", "collapsed": false, "input": [ "lt = [('one', 1), ('two', 2), ('three', 3)]\n", "for name, num in lt:\n", " print name, num" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "one 1\n", "two 2\n", "three 3\n" ] } ], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \uc548\uc758 \uac01 \uc790\ub8cc\uac00 \ub9ac\uc2a4\ud2b8\uc5ec\ub3c4 for \ubb38\uc758 \ud5e4\ub354\uc5d0\uc11c \ub3d9\uc77c\ud558\uac8c \uac12 \ucd94\ucd9c \uac00\ub2a5" ] }, { "cell_type": "code", "collapsed": false, "input": [ "LL = [['one', 1], ['two', 2], ['three', 3]]\n", "for name, num in LL:\n", " print name, num" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "one 1\n", "two 2\n", "three 3\n" ] } ], "prompt_number": 38 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 05 \uc6d0\ud558\ub294 \uc21c\uc11c\ub300\ub85c \uc815\ub82c\ud558\uae30-sort\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 5-1 \ub9ac\uc2a4\ud2b8\uc758 sort \uba54\uc3d8\ub4dc" ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 5, 3, 9, 8, 4, 2]\n", "L.sort()\n", "L" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 44, "text": [ "[1, 2, 3, 4, 5, 8, 9]" ] } ], "prompt_number": 44 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ud30c\uc774\uc36c\uc740 \ub514\ud3f4\ud2b8\ub85c cmp(a, b) \ub0b4\uc7a5 \ud568\uc218\ub97c \uc774\uc6a9\ud558\uc5ec \uc815\ub82c \ubc29\uc2dd\uc744 \uacb0\uc815\ud55c\ub2e4.\n", "- cmp(a, b)\n", " - if a < b: return -1\n", " - if a > b: return 1\n", " - if a == b: return 0" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print cmp(1,2)\n", "\n", "print cmp(5,2)\n", "\n", "print cmp('abc', 'abc')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "-1\n", "1\n", "0\n" ] } ], "prompt_number": 45 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uae30\ubcf8 \uc815\ub82c \ubc29\uc2dd\uc744 \ubcc0\uacbd\ud558\ub824\uba74 cmp(a, b)\uc640 \uac19\uc740 \ube44\uad50 \ud568\uc218\ub97c \uc9c1\uc811 \ub9cc\ub4e4\uc5b4\uc11c sort() \ud568\uc218\uc758 \uc778\uc790\ub85c \ub123\ub294\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "def mycmp(a1, a2): # \ub300\uc18c\uad00\uacc4\uc5d0 \ub530\ub978 \uc21c\uc11c\ub97c \ubc18\ub300\ub85c \ubc14\uafb8\uc5c8\uc74c\n", " return cmp(a2, a1)\n", "\n", "L = [1, 5, 3, 2, 4, 6]\n", "L.sort(mycmp) # \uc5ed\uc21c\uc73c\ub85c \uc815\ub82c\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[6, 5, 4, 3, 2, 1]\n" ] } ], "prompt_number": 14 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc5ec\ub7ec \ud29c\ud50c\uc744 \uc694\uc18c\ub85c \uc9c0\ub2cc \ub9ac\uc2a4\ud2b8\uc778 \uacbd\uc6b0, \ud29c\ud50c\uc758 \uccab\ubc88\uc9f8 \uac12\uc774 \uc544\ub2cc \ub2e4\ub978 \uc704\uce58\uc5d0 \uc788\ub294 \uac12\uc744 \uae30\uc900\uc73c\ub85c \uc815\ub82c " ] }, { "cell_type": "code", "collapsed": false, "input": [ "def cmp_1(a1, a2):\n", " return cmp(a1[1], a2[1])\n", "\n", "def cmp_2(a1, a2):\n", " return cmp(a1[2], a2[2])\n", "\n", "L = [ ('lee', 5, 38), ('kim', 3, 28), ('jung', 10, 36)]\n", "L.sort()\n", "print 'sorted by name:', L\n", "\n", "L.sort(cmp_1)\n", "print 'sorted by experience:', L\n", "\n", "L.sort(cmp_2)\n", "print 'sorted by age:', L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "sorted by name: [('jung', 10, 36), ('kim', 3, 28), ('lee', 5, 38)]\n", "sorted by experience: [('kim', 3, 28), ('lee', 5, 38), ('jung', 10, 36)]\n", "sorted by age: [('kim', 3, 28), ('jung', 10, 36), ('lee', 5, 38)]\n" ] } ], "prompt_number": 49 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Python 2.4 \ubd80\ud130\ub294 sort() \ud568\uc218 \uc778\uc790\ub85c reverse \uac12\uc744 \ubc1b\uc744 \uc218 \uc788\ub3c4\ub85d \uc218\uc815\ub418\uc5c8\ub2e4.\n", " - reverse \uc778\uc790\uac12\uc744 True\ub85c \uc8fc\uba74 \uc5ed\uc21c\uc73c\ub85c \uc815\ub82c\ub428" ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "L.sort(reverse = True)\n", "L" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 56, "text": [ "[9, 8, 6, 6, 3, 2, 1]" ] } ], "prompt_number": 56 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- sort() \ud568\uc218 \uc778\uc790\ub85c key\uc5d0 \ud568\uc218\ub97c \ub123\uc5b4\uc904 \uc218 \uc788\ub2e4.\n", " - \uac01 \ub9ac\uc2a4\ud2b8 \uc6d0\uc18c\uc5d0 \ub300\ud574 \ube44\uad50\ud568\uc218\ub97c \ud638\ucd9c \uc9c1\uc804\uc5d0 key \ud568\uc218\ub97c \uba3c\uc800 \ud638\ucd9c\ud55c\ub2e4. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = ['123', '34', '56', '2345']\n", "L.sort()\n", "print L\n", "\n", "L.sort(key=int)\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['123', '2345', '34', '56']\n", "['34', '56', '123', '2345']\n" ] } ], "prompt_number": 51 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 5-2 sorted \ub0b4\uc7a5 \ud568\uc218\n", "- L.sort() \ud568\uc218\ub294 \ub9ac\ud134\uac12\uc744 \ubc18\ud658\ud558\uc9c0 \uc54a\ub294\ub2e4.\n", " - \uc989, L \uc790\uccb4\ub97c \uc815\ub82c\ud558\uc5ec \ubcc0\uacbd\ud55c\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "newList = L.sort()\n", "print newList\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "None\n", "[1, 2, 3, 6, 6, 8, 9]\n" ] } ], "prompt_number": 19 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- sorted() \ub0b4\uc7a5\ud568\uc218\ub294 L \uc790\uccb4\uc5d0\ub294 \ub0b4\uc6a9 \ubcc0\uacbd \uc5c6\uc774 \uc815\ub82c\uc774 \ub418\uc5b4\uc9c4 \uc0c8\ub85c\uc6b4 \ub9ac\uc2a4\ud2b8\ub97c \ubc18\ud658\ud55c\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "newList = sorted(L)\n", "print newList\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 2, 3, 6, 6, 8, 9]\n", "[1, 6, 3, 8, 6, 2, 9]\n" ] } ], "prompt_number": 15 }, { "cell_type": "code", "collapsed": false, "input": [ "for ele in sorted(L):\n", " print ele," ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1 2 3 6 6 8 9\n" ] } ], "prompt_number": 55 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- sorted() \ud568\uc218\uc758 \ub450\ubc88\uc9f8 \uc778\uc790\ub85c cmp \ud568\uc218 \uc9c0\uc815 \uac00\ub2a5" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def mycmp(a1, a2): # \ub300\uc18c\uad00\uacc4\uc5d0 \ub530\ub978 \uc21c\uc11c\ub97c \ubc18\ub300\ub85c \ubc14\uafb8\uc5c8\uc74c\n", " return cmp(a2, a1)\n", "\n", "L = [1, 5, 3, 2, 4, 6]\n", "print sorted(L, mycmp) # \uc5ed\uc21c\uc73c\ub85c \uc815\ub82c\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[6, 5, 4, 3, 2, 1]\n", "[1, 5, 3, 2, 4, 6]\n" ] } ], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc778\uc790\ub85c reverse\uc640 key \uc9c0\uc815 \uac00\ub2a5" ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "print sorted(L, reverse=True)\n", "\n", "L = ['123', '34', '56', '2345']\n", "print sorted(L, key=int)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[9, 8, 6, 6, 3, 2, 1]\n", "['34', '56', '123', '2345']\n" ] } ], "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 5-3 reversed \ub0b4\uc7a5 \ud568\uc218\n", "- L.reverse()\ub3c4 \ubc18\ud658\uac12\uc774 \uc5c6\ub2e4.\n", " - \uc989, L \uc790\uccb4\ub97c \uc5ed\uc21c\uc73c\ub85c \ub4a4\uc9d1\ub294\ub2e4.\n", " - [\uc8fc\uc758] \uc5ed\uc21c \uc815\ub82c\uc774 \uc544\ub2c8\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "r = L.reverse()\n", "print r\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "None\n", "[9, 2, 6, 8, 3, 6, 1]\n" ] } ], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "L.reverse() # \uc5ed\uc21c\uc73c\ub85c \ub4a4\uc9d1\ub294\ub2e4.\n", "for ele in L:\n", " print ele + 2,\n", "\n", "print\n", "L.reverse() # \ub2e4\uc2dc \uc6d0\uc0c1\ud0dc\ub85c \ubcf5\uadc0\uc2dc\ud0a8\ub2e4.\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "11 4 8 10 5 8 3\n", "[1, 6, 3, 8, 6, 2, 9]\n" ] } ], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- reversed() \ub0b4\uc7a5\ud568\uc218\ub294 sorted() \ucc98\ub7fc \ub0b4\uc6a9\uc774 \ub4a4\uc9d1\ud78c \ub9ac\uc2a4\ud2b8\ub97c \ubc18\ud658\ud55c\ub2e4.\n", " - sorted() \ucc98\ub7fc \uc6d0\ub798 \ub9ac\uc2a4\ud2b8 \ub0b4\uc6a9\uc5d0\ub294 \ubcc0\ud568\uc5c6\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [1, 6, 3, 8, 6, 2, 9]\n", "print L\n", "for ele in reversed(L):\n", " print ele + 2, \n", "print\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 6, 3, 8, 6, 2, 9]\n", "11 4 8 10 5 8 3\n", "[1, 6, 3, 8, 6, 2, 9]\n" ] } ], "prompt_number": 31 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 06 \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec(List Comprehension)\n", "***\n", "- \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec\ub294 \ud568\uc218\uc801 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc778 Haskell (http://www.haskell.org )\uc5d0\uc11c \uadf8 \ud615\uc2dd\uc744 \ub530\uc628 \uac83 " ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = []\n", "for k in range(10):\n", " L.append(k*k)\n", " \n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n" ] } ], "prompt_number": 74 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc704 \ucf54\ub529\uc740 \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec \ub9ac\ud130\ub7f4 \ubc29\uc2dd\uc744 \ud65c\uc6a9\ud574\uc11c \uc544\ub798\uc640 \uac19\uc774 \ubcc0\uacbd\ud560 \uc218 \uc788\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [k * k for k in range(10)]\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n" ] } ], "prompt_number": 32 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec \ub9ac\ud130\ub7f4\n", "
\n",
      "[expression for expr1 in sequence1\n",
      "              for expr2 in sequence2 \n",
      "              ...\n",
      "              for exprN in sequenceN\n",
      "              if condition]\n",
      "
\n", "- expression\uc758 \ud3c9\uac00 \uacb0\uacfc \ubc18\ub4dc\uc2dc \ud55c \uac1c\uc758 \uc6d0\uc18c\uac00 \ub098\uc640\uc57c \ud55c\ub2e4.\n", " - \ud2c0\ub9b0 \uc608: [ x, y for x in seq1 for u in seq2 ]\n", "- \ub9cc\uc57d \ub450 \uac1c\uc758 \uc774\uc0c1\uc758 \ud3c9\uac00 \uacb0\uacfc\uac00 \ub098\uc624\uba74 \ud29c\ud50c \ub4f1\uc73c\ub85c \uac10\uc2f8 \uc8fc\uc5b4\uc57c \ud55c\ub2e4.\n", " - \uc62c\ubc14\ub978 \uc608: [ (x, y) for x in seq1 for u in seq2 ]\n", "- \uc704 \ub9ac\ud130\ub7f4\uc740 \ub2e4\uc74c\uc758 \uc77c\ubc18\uc801\uc778 for \ubb38\uc758 \ub9ac\ud138\ub7ec\uacfc \ub3d9\uc77c\n", "
\n",
      "l = []\n",
      "for expr1 in sequence1:\n",
      "   for expr2 in sequence2:\n",
      "      ...\n",
      "         for exprtN in sequenceN:\n",
      "            if condition:\n",
      "               l.append(expression)\n",
      "
\n", " " ] }, { "cell_type": "code", "collapsed": false, "input": [ "L = [k * k for k in range(10) if k % 2] # \ud640\uc218\uc758 \uc81c\uacf1\ub9cc \ub9ac\uc2a4\ud2b8\ub85c \ud615\uc131\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 9, 25, 49, 81]\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "L = []\n", "for k in range(10):\n", " if k%2:\n", " L.append(k*k)\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 9, 25, 49, 81]\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 100\ubcf4\ub2e4 \uc791\uc740 2\uc758 \ubc30\uc218\uc640 3\uc758 \ubc30\uc218\uc5d0 \ub300\ud574 \uadf8 \ub450 \uc218\uc758 \ud569\uc774 7\uc758 \ubc30\uc218\uc778 \uac83\ub4e4\uc5d0 \ub300\ud574 \uadf8 \ub450 \uc218\uc758 \uacf1\uc744 \ucd9c\ub825\ud558\ub294 \ucf54\ub4dc" ] }, { "cell_type": "code", "collapsed": false, "input": [ "[(i, j, i*j) for i in range(2, 100, 2)\n", " for j in range(3, 100, 3)\n", " if (i + j) % 7 == 0]\n" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 12, "text": [ "[(2, 12, 24),\n", " (2, 33, 66),\n", " (2, 54, 108),\n", " (2, 75, 150),\n", " (2, 96, 192),\n", " (4, 3, 12),\n", " (4, 24, 96),\n", " (4, 45, 180),\n", " (4, 66, 264),\n", " (4, 87, 348),\n", " (6, 15, 90),\n", " (6, 36, 216),\n", " (6, 57, 342),\n", " (6, 78, 468),\n", " (6, 99, 594),\n", " (8, 6, 48),\n", " (8, 27, 216),\n", " (8, 48, 384),\n", " (8, 69, 552),\n", " (8, 90, 720),\n", " (10, 18, 180),\n", " (10, 39, 390),\n", " (10, 60, 600),\n", " (10, 81, 810),\n", " (12, 9, 108),\n", " (12, 30, 360),\n", " (12, 51, 612),\n", " (12, 72, 864),\n", " (12, 93, 1116),\n", " (14, 21, 294),\n", " (14, 42, 588),\n", " (14, 63, 882),\n", " (14, 84, 1176),\n", " (16, 12, 192),\n", " (16, 33, 528),\n", " (16, 54, 864),\n", " (16, 75, 1200),\n", " (16, 96, 1536),\n", " (18, 3, 54),\n", " (18, 24, 432),\n", " (18, 45, 810),\n", " (18, 66, 1188),\n", " (18, 87, 1566),\n", " (20, 15, 300),\n", " (20, 36, 720),\n", " (20, 57, 1140),\n", " (20, 78, 1560),\n", " (20, 99, 1980),\n", " (22, 6, 132),\n", " (22, 27, 594),\n", " (22, 48, 1056),\n", " (22, 69, 1518),\n", " (22, 90, 1980),\n", " (24, 18, 432),\n", " (24, 39, 936),\n", " (24, 60, 1440),\n", " (24, 81, 1944),\n", " (26, 9, 234),\n", " (26, 30, 780),\n", " (26, 51, 1326),\n", " (26, 72, 1872),\n", " (26, 93, 2418),\n", " (28, 21, 588),\n", " (28, 42, 1176),\n", " (28, 63, 1764),\n", " (28, 84, 2352),\n", " (30, 12, 360),\n", " (30, 33, 990),\n", " (30, 54, 1620),\n", " (30, 75, 2250),\n", " (30, 96, 2880),\n", " (32, 3, 96),\n", " (32, 24, 768),\n", " (32, 45, 1440),\n", " (32, 66, 2112),\n", " (32, 87, 2784),\n", " (34, 15, 510),\n", " (34, 36, 1224),\n", " (34, 57, 1938),\n", " (34, 78, 2652),\n", " (34, 99, 3366),\n", " (36, 6, 216),\n", " (36, 27, 972),\n", " (36, 48, 1728),\n", " (36, 69, 2484),\n", " (36, 90, 3240),\n", " (38, 18, 684),\n", " (38, 39, 1482),\n", " (38, 60, 2280),\n", " (38, 81, 3078),\n", " (40, 9, 360),\n", " (40, 30, 1200),\n", " (40, 51, 2040),\n", " (40, 72, 2880),\n", " (40, 93, 3720),\n", " (42, 21, 882),\n", " (42, 42, 1764),\n", " (42, 63, 2646),\n", " (42, 84, 3528),\n", " (44, 12, 528),\n", " (44, 33, 1452),\n", " (44, 54, 2376),\n", " (44, 75, 3300),\n", " (44, 96, 4224),\n", " (46, 3, 138),\n", " (46, 24, 1104),\n", " (46, 45, 2070),\n", " (46, 66, 3036),\n", " (46, 87, 4002),\n", " (48, 15, 720),\n", " (48, 36, 1728),\n", " (48, 57, 2736),\n", " (48, 78, 3744),\n", " (48, 99, 4752),\n", " (50, 6, 300),\n", " (50, 27, 1350),\n", " (50, 48, 2400),\n", " (50, 69, 3450),\n", " (50, 90, 4500),\n", " (52, 18, 936),\n", " (52, 39, 2028),\n", " (52, 60, 3120),\n", " (52, 81, 4212),\n", " (54, 9, 486),\n", " (54, 30, 1620),\n", " (54, 51, 2754),\n", " (54, 72, 3888),\n", " (54, 93, 5022),\n", " (56, 21, 1176),\n", " (56, 42, 2352),\n", " (56, 63, 3528),\n", " (56, 84, 4704),\n", " (58, 12, 696),\n", " (58, 33, 1914),\n", " (58, 54, 3132),\n", " (58, 75, 4350),\n", " (58, 96, 5568),\n", " (60, 3, 180),\n", " (60, 24, 1440),\n", " (60, 45, 2700),\n", " (60, 66, 3960),\n", " (60, 87, 5220),\n", " (62, 15, 930),\n", " (62, 36, 2232),\n", " (62, 57, 3534),\n", " (62, 78, 4836),\n", " (62, 99, 6138),\n", " (64, 6, 384),\n", " (64, 27, 1728),\n", " (64, 48, 3072),\n", " (64, 69, 4416),\n", " (64, 90, 5760),\n", " (66, 18, 1188),\n", " (66, 39, 2574),\n", " (66, 60, 3960),\n", " (66, 81, 5346),\n", " (68, 9, 612),\n", " (68, 30, 2040),\n", " (68, 51, 3468),\n", " (68, 72, 4896),\n", " (68, 93, 6324),\n", " (70, 21, 1470),\n", " (70, 42, 2940),\n", " (70, 63, 4410),\n", " (70, 84, 5880),\n", " (72, 12, 864),\n", " (72, 33, 2376),\n", " (72, 54, 3888),\n", " (72, 75, 5400),\n", " (72, 96, 6912),\n", " (74, 3, 222),\n", " (74, 24, 1776),\n", " (74, 45, 3330),\n", " (74, 66, 4884),\n", " (74, 87, 6438),\n", " (76, 15, 1140),\n", " (76, 36, 2736),\n", " (76, 57, 4332),\n", " (76, 78, 5928),\n", " (76, 99, 7524),\n", " (78, 6, 468),\n", " (78, 27, 2106),\n", " (78, 48, 3744),\n", " (78, 69, 5382),\n", " (78, 90, 7020),\n", " (80, 18, 1440),\n", " (80, 39, 3120),\n", " (80, 60, 4800),\n", " (80, 81, 6480),\n", " (82, 9, 738),\n", " (82, 30, 2460),\n", " (82, 51, 4182),\n", " (82, 72, 5904),\n", " (82, 93, 7626),\n", " (84, 21, 1764),\n", " (84, 42, 3528),\n", " (84, 63, 5292),\n", " (84, 84, 7056),\n", " (86, 12, 1032),\n", " (86, 33, 2838),\n", " (86, 54, 4644),\n", " (86, 75, 6450),\n", " (86, 96, 8256),\n", " (88, 3, 264),\n", " (88, 24, 2112),\n", " (88, 45, 3960),\n", " (88, 66, 5808),\n", " (88, 87, 7656),\n", " (90, 15, 1350),\n", " (90, 36, 3240),\n", " (90, 57, 5130),\n", " (90, 78, 7020),\n", " (90, 99, 8910),\n", " (92, 6, 552),\n", " (92, 27, 2484),\n", " (92, 48, 4416),\n", " (92, 69, 6348),\n", " (92, 90, 8280),\n", " (94, 18, 1692),\n", " (94, 39, 3666),\n", " (94, 60, 5640),\n", " (94, 81, 7614),\n", " (96, 9, 864),\n", " (96, 30, 2880),\n", " (96, 51, 4896),\n", " (96, 72, 6912),\n", " (96, 93, 8928),\n", " (98, 21, 2058),\n", " (98, 42, 4116),\n", " (98, 63, 6174),\n", " (98, 84, 8232)]" ] } ], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub450 \uac1c\uc758 \uc2dc\ud000\uc2a4 \uc790\ub8cc\ud615\uc5d0 \ub300\ud574 \uac01\uac01\uc758 \uc6d0\uc18c\uc5d0 \ub300\ud55c \uc30d\uc744 \ud29c\ud50c \ud615\ud0dc\ub85c \ub9cc\ub4e4\uba74\uc11c \ub9ac\uc2a4\ud2b8\uc5d0 \uc800\uc7a5\ud558\ub294 \ucf54\ub4dc" ] }, { "cell_type": "code", "collapsed": false, "input": [ "seq1 = 'abc'\n", "seq2 = (1, 2, 3)\n", "[ (x, y) for x in seq1 for y in seq2]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 77, "text": [ "[('a', 1),\n", " ('a', 2),\n", " ('a', 3),\n", " ('b', 1),\n", " ('b', 2),\n", " ('b', 3),\n", " ('c', 1),\n", " ('c', 2),\n", " ('c', 3)]" ] } ], "prompt_number": 77 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub2e4\uc74c\uc740 \uace0\ub4f1\ud559\uad50 \uc218\ud559\uc5d0\uc11c \ubc30\uc6b4 \uc9d1\ud569\uc758 \ud45c\uae30 \ubc29\ubc95\uc774\ub2e4.\n", " - A = {x^2 | x in {0, ..., 9}}\n", " - B = {1, 2, 4, 8, 16, ..., 2^16}\n", " - C = {x | x in S and x is odd}\n", "\n", "- \ud30c\uc774\uc36c\uc758 \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec(list comprehension)\ub294 \ubc14\ub85c \uc704 \uc9d1\ud569 \ud45c\uae30\ubc95\uacfc \uc720\uc0ac\ud55c \ubc29\uc2dd\uc758 \ub9ac\ud130\ub7f4\uc774\ub2e4. \n", "- \uc704 \uc9d1\ud569\ub4e4\uc744 \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec \ubc29\uc2dd\uc73c\ub85c \ud45c\ud604\ud558\uba74 \ub2e4\uc74c\uacfc \uac19\ub2e4. \n", " - A = [x**2 for x in range(10)]\n", " - B = [2**i for i in range(17)]\n", " - C = [x for x in S if x % 2 == 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec \ubc29\uc2dd\uc744 \uc0ac\uc6a9\ud574 \ubb38\uc790\uc5f4 \ub2e4\ub8e8\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "words = 'The quick brown fox jumps over the lazy and fast dog'.split()\n", "stuff = [w for w in words if w.startswith('f')]\n", "print stuff" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['fox', 'fast']\n" ] } ], "prompt_number": 15 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ud53c\ud0c0\uace0\ub77c\uc2a4 \uc0bc\uac01\ud615\uc758 \uac01 3\ubcc0\uc758 \uae38\uc774 \ub9ac\uc2a4\ud2b8" ] }, { "cell_type": "code", "collapsed": false, "input": [ "[(x,y,z) for x in range(1,30) for y in range(x,30) for z in range(y,30) if x**2 + y**2 == z**2]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "[(3, 4, 5),\n", " (5, 12, 13),\n", " (6, 8, 10),\n", " (7, 24, 25),\n", " (8, 15, 17),\n", " (9, 12, 15),\n", " (10, 24, 26),\n", " (12, 16, 20),\n", " (15, 20, 25),\n", " (20, 21, 29)]" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ubb38\uc790\uc5f4 \ub9ac\uc2a4\ud2b8\ub97c \uc0ac\uc6a9\ud574 \ub9ac\uc2a4\ud2b8\uc758 \ub9ac\uc2a4\ud2b8 \uc0dd\uc131" ] }, { "cell_type": "code", "collapsed": false, "input": [ "words = 'The quick brown fox jumps over the lazy dog'.split()\n", "stuff = [[w.upper(), w.lower(), len(w)] for w in words]\n", "for i in stuff:\n", " print i" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['THE', 'the', 3]\n", "['QUICK', 'quick', 5]\n", "['BROWN', 'brown', 5]\n", "['FOX', 'fox', 3]\n", "['JUMPS', 'jumps', 5]\n", "['OVER', 'over', 4]\n", "['THE', 'the', 3]\n", "['LAZY', 'lazy', 4]\n", "['DOG', 'dog', 3]\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc911\ucca9 \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec" ] }, { "cell_type": "code", "collapsed": false, "input": [ "list_a = ['A', 'B']\n", "list_b = ['C', 'D']\n", "print [x+y for x in list_a for y in list_b]\n", "print\n", "print [[x+y for x in list_a] for y in list_b]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['AC', 'AD', 'BC', 'BD']\n", "\n", "[['AC', 'BC'], ['AD', 'BD']]\n" ] } ], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc704 \uc608\uc81c\uc758 \ub9c8\uc9c0\ub9c9 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \ub3d9\uc77c\ud558\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "l = []\n", "for y in list_b:\n", " l2 = []\n", " for x in list_a:\n", " l2.append(x+y)\n", " l.append(l2)\n", "print l" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[['AC', 'BC'], ['AD', 'BD']]\n" ] } ], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 07 \uc21c\ud658 \ucc38\uc870(Cyclic Reference) \ub9ac\uc2a4\ud2b8\n", "***\n", "- \uc21c\ud658 \ucc38\uc870: \uc5b4\ub5a4 \uac1d\uccb4\uac00 \uc790\uae30 \uc790\uc2e0\uc744 \uc9c1\uc811 \ud639\uc740 \uac04\uc811\uc801\uc73c\ub85c \ucc38\uc870\ud558\ub294 \uac83" ] }, { "cell_type": "code", "collapsed": false, "input": [ "CL = ['is fun']\n", "CL.insert(0, CL)\n", "print CL\n", "\n", "print CL[0]\n", "\n", "print CL[0][0]\n", "\n", "print CL[0][0][0]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[[...], 'is fun']\n", "[[...], 'is fun']\n", "[[...], 'is fun']\n", "[[...], 'is fun']\n" ] } ], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](images/cyclic_ref.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 08 range-\uc21c\ucc28\uc801\uc778 \uc815\uc218 \ub9ac\uc2a4\ud2b8 \ub9cc\ub4e4\uae30\n", "***" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print range(10) # 0(Included)\ubd80\ud130 10(Excluded)\uae4c\uc9c0\n", "\n", "print range(5, 15) # 5(Included)\ubd80\ud130 15(Excluded)\uae4c\uc9c0\n", "\n", "print range(5, 15, 2) # 0(Included)\ubd80\ud130 10(Excluded)\uae4c\uc9c0, Step: 2\n", "\n", "print range(0, -10, -1) # 0(Included)\ubd80\ud130 -10(Excluded)\uae4c\uc9c0, Step: -1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", "[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n", "[5, 7, 9, 11, 13]\n", "[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "for el in range(10):\n", " print el, 'inch=', el * 2.54, 'centi'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0 inch= 0.0 centi\n", "1 inch= 2.54 centi\n", "2 inch= 5.08 centi\n", "3 inch= 7.62 centi\n", "4 inch= 10.16 centi\n", "5 inch= 12.7 centi\n", "6 inch= 15.24 centi\n", "7 inch= 17.78 centi\n", "8 inch= 20.32 centi\n", "9 inch= 22.86 centi\n" ] } ], "prompt_number": 80 }, { "cell_type": "code", "collapsed": false, "input": [ "sun, mon, tue, wed, thu, fri, sat = range(7)\n", "print sun, mon, tue, wed, thu, fri, sat" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0 1 2 3 4 5 6\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 09 \ub85c\uceec \ub0b4\uc5d0\uc11c \uc0ac\uc6a9 \uac00\ub2a5\ud55c \uc2ec\ubcfc \ud14c\uc774\ube14 \ub0b4\uc6a9 \uc5bb\uae30\n", "***\n", "- dir(): \uc9c0\uc5ed\uc801\uc73c\ub85c \uc0ac\uc6a9\uac00\ub2a5\ud55c \uc18d\uc131(\uba64\ubc84 \ubcc0\uc218 \ubc0f \ud568\uc218) \ubaa9\ub85d \ub9ac\uc2a4\ud2b8 \ubc18\ud658\n", "- dir(object): object \uac1d\uccb4\uac00 \uc9c0\ub2cc \uc18d\uc131(\uba64\ubc84 \ubcc0\uc218 \ubc0f \ud568\uc218) \ubaa9\ub85d \ub9ac\uc2a4\ud2b8 \ubc18\ud658" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print dir()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['ALLOW_THREADS', 'Annotation', 'Arrow', 'Artist', 'AutoLocator', 'Axes', 'BUFSIZE', 'Button', 'CLIP', 'Circle', 'ComplexWarning', 'DAILY', 'DataSource', 'DateFormatter', 'DateLocator', 'DayLocator', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'FR', 'False_', 'Figure', 'FigureCanvasBase', 'FixedFormatter', 'FixedLocator', 'FormatStrFormatter', 'Formatter', 'FuncFormatter', 'GridSpec', 'HOURLY', 'HourLocator', 'In', 'IndexDateFormatter', 'IndexLocator', 'Inf', 'Infinity', 'LinAlgError', 'Line2D', 'LinearLocator', 'Locator', 'LogFormatter', 'LogFormatterExponent', 'LogFormatterMathtext', 'LogLocator', 'MAXDIMS', 'MINUTELY', 'MO', 'MONTHLY', 'MachAr', 'MaxNLocator', 'MinuteLocator', 'ModuleDeprecationWarning', 'MonthLocator', 'MultipleLocator', 'NAN', 'NINF', 'NZERO', 'NaN', 'Normalize', 'NullFormatter', 'NullLocator', 'Out', 'PINF', 'PZERO', 'PackageLoader', 'PolarAxes', 'Polygon', 'RAISE', 'RRuleLocator', 'RankWarning', 'Rectangle', 'SA', 'SECONDLY', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'SU', 'ScalarFormatter', 'ScalarType', 'SecondLocator', 'Slider', 'Subplot', 'SubplotTool', 'TH', 'TU', 'Tester', 'Text', 'TickHelper', 'True_', 'UFUNC_BUFSIZE_DEFAULT', 'UFUNC_PYVALS_NAME', 'WE', 'WEEKLY', 'WRAP', 'WeekdayLocator', 'Widget', 'YEARLY', 'YearLocator', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__name__', '__version__', '_dh', '_i', '_i1', '_i2', '_i3', '_ih', '_ii', '_iii', '_oh', '_sh', 'absolute', 'absolute_import', 'acorr', 'add', 'add_docstring', 'add_newdoc', 'add_newdoc_ufunc', 'add_newdocs', 'alen', 'all', 'allclose', 'alltrue', 'alterdot', 'amap', 'amax', 'amin', 'angle', 'annotate', 'any', 'append', 'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin', 'argpartition', 'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal', 'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrow', 'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray', 'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'autoscale', 'autumn', 'average', 'axes', 'axhline', 'axhspan', 'axis', 'axvline', 'axvspan', 'bar', 'barbs', 'barh', 'bartlett', 'base_repr', 'bench', 'beta', 'binary_repr', 'bincount', 'binomial', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'bivariate_normal', 'blackman', 'bmat', 'bone', 'bool8', 'bool_', 'box', 'boxplot', 'broadcast', 'broadcast_arrays', 'broken_barh', 'busday_count', 'busday_offset', 'busdaycalendar', 'byte', 'byte_bounds', 'bytes', 'bytes_', 'c_', 'can_cast', 'cast', 'cbook', 'cdouble', 'ceil', 'center_matrix', 'cfloat', 'char', 'character', 'chararray', 'chisquare', 'cholesky', 'choose', 'cla', 'clabel', 'clf', 'clim', 'clip', 'clongdouble', 'clongfloat', 'close', 'cm', 'cohere', 'colorbar', 'colormaps', 'colors', 'column_stack', 'common_type', 'compare_chararrays', 'complex128', 'complex256', 'complex64', 'complex_', 'complexfloating', 'compress', 'concatenate', 'cond', 'conj', 'conjugate', 'connect', 'contour', 'contourf', 'convolve', 'cool', 'copper', 'copy', 'copysign', 'copyto', 'corrcoef', 'correlate', 'cos', 'cosh', 'count_nonzero', 'cov', 'cross', 'csd', 'csingle', 'csv2rec', 'ctypeslib', 'cumprod', 'cumproduct', 'cumsum', 'date2num', 'datestr2num', 'datetime', 'datetime64', 'datetime_as_string', 'datetime_data', 'dedent', 'deg2rad', 'degrees', 'delaxes', 'delete', 'demean', 'deprecate', 'deprecate_with_doc', 'det', 'detrend', 'detrend_linear', 'detrend_mean', 'detrend_none', 'diag', 'diag_indices', 'diag_indices_from', 'diagflat', 'diagonal', 'diff', 'digitize', 'disconnect', 'disp', 'display', 'dist', 'dist_point_to_segment', 'distances_along_curve', 'divide', 'division', 'docstring', 'dot', 'double', 'drange', 'draw', 'draw_if_interactive', 'dsplit', 'dstack', 'dtype', 'e', 'ediff1d', 'eig', 'eigh', 'eigvals', 'eigvalsh', 'einsum', 'emath', 'empty', 'empty_like', 'entropy', 'epoch2num', 'equal', 'errorbar', 'errstate', 'euler_gamma', 'eventplot', 'exception_to_str', 'exit', 'exp', 'exp2', 'exp_safe', 'expand_dims', 'expm1', 'exponential', 'extract', 'eye', 'f', 'fabs', 'fastCopyAndTranspose', 'fft', 'fft2', 'fftfreq', 'fftn', 'fftpack', 'fftpack_lite', 'fftshift', 'fftsurr', 'figaspect', 'figimage', 'figlegend', 'fignum_exists', 'figsize', 'figtext', 'figure', 'fill', 'fill_between', 'fill_betweenx', 'fill_diagonal', 'find', 'find_common_type', 'findobj', 'finfo', 'fix', 'flag', 'flatiter', 'flatnonzero', 'flatten', 'flexible', 'fliplr', 'flipud', 'float128', 'float16', 'float32', 'float64', 'float_', 'floating', 'floor', 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', 'frange', 'frexp', 'fri', 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromregex', 'fromstring', 'full', 'full_like', 'fv', 'gamma', 'gca', 'gcf', 'gci', 'generic', 'genfromtxt', 'geometric', 'get', 'get_array_wrap', 'get_backend', 'get_cmap', 'get_current_fig_manager', 'get_figlabels', 'get_fignums', 'get_include', 'get_ipython', 'get_numarray_include', 'get_plot_commands', 'get_printoptions', 'get_scale_docs', 'get_scale_names', 'get_sparse_matrix', 'get_state', 'get_xyz_where', 'getbuffer', 'getbufsize', 'geterr', 'geterrcall', 'geterrobj', 'getfigs', 'getp', 'ginput', 'gradient', 'gray', 'greater', 'greater_equal', 'grid', 'griddata', 'gumbel', 'half', 'hamming', 'hanning', 'helper', 'hexbin', 'hfft', 'hist', 'hist2d', 'histogram', 'histogram2d', 'histogramdd', 'hlines', 'hold', 'hot', 'hsplit', 'hstack', 'hsv', 'hypergeometric', 'hypot', 'i0', 'identity', 'ifft', 'ifft2', 'ifftn', 'ifftshift', 'ihfft', 'iinfo', 'imag', 'imread', 'imsave', 'imshow', 'in1d', 'index_exp', 'indices', 'inexact', 'inf', 'info', 'infty', 'inner', 'insert', 'inside_poly', 'int0', 'int16', 'int32', 'int64', 'int8', 'int_', 'int_asbuffer', 'intc', 'integer', 'interactive', 'interp', 'intersect1d', 'intp', 'inv', 'invert', 'ioff', 'ion', 'ipmt', 'irfft', 'irfft2', 'irfftn', 'irr', 'is_busday', 'is_closed_polygon', 'is_numlike', 'is_string_like', 'isclose', 'iscomplex', 'iscomplexobj', 'isfinite', 'isfortran', 'ishold', 'isinf', 'isinteractive', 'isnan', 'isneginf', 'isposinf', 'ispower2', 'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_', 'issubdtype', 'issubsctype', 'isvector', 'iterable', 'ix_', 'jet', 'kaiser', 'kron', 'l1norm', 'l2norm', 'lapack_lite', 'laplace', 'ldexp', 'left_shift', 'legend', 'less', 'less_equal', 'levypdf', 'lexsort', 'linalg', 'linspace', 'little_endian', 'load', 'loads', 'loadtxt', 'locator_params', 'log', 'log10', 'log1p', 'log2', 'logaddexp', 'logaddexp2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logistic', 'loglog', 'lognormal', 'logseries', 'logspace', 'longcomplex', 'longdouble', 'longest_contiguous_ones', 'longest_ones', 'longfloat', 'longlong', 'lookfor', 'lstsq', 'ma', 'mafromtxt', 'margins', 'mask_indices', 'mat', 'math', 'matplotlib', 'matrix', 'matrix_power', 'matrix_rank', 'matshow', 'maximum', 'maximum_sctype', 'may_share_memory', 'mean', 'median', 'memmap', 'meshgrid', 'mgrid', 'min_scalar_type', 'minimum', 'minorticks_off', 'minorticks_on', 'mintypecode', 'mirr', 'mlab', 'mod', 'modf', 'mon', 'movavg', 'mpl', 'msort', 'multinomial', 'multiply', 'multivariate_normal', 'mx2num', 'nan', 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmean', 'nanmin', 'nanstd', 'nansum', 'nanvar', 'nbytes', 'ndarray', 'ndenumerate', 'ndfromtxt', 'ndim', 'ndindex', 'nditer', 'negative', 'negative_binomial', 'nested_iters', 'new_figure_manager', 'newaxis', 'newbuffer', 'nextafter', 'noncentral_chisquare', 'noncentral_f', 'nonzero', 'norm', 'norm_flat', 'normal', 'normalize', 'normpdf', 'not_equal', 'np', 'nper', 'npv', 'num2date', 'num2epoch', 'number', 'numpy', 'obj2sctype', 'object0', 'object_', 'ogrid', 'ones', 'ones_like', 'outer', 'over', 'packbits', 'pad', 'pareto', 'partition', 'path_length', 'pause', 'pcolor', 'pcolormesh', 'percentile', 'permutation', 'pi', 'pie', 'piecewise', 'pink', 'pinv', 'pkgload', 'place', 'plot', 'plot_date', 'plotfile', 'plotting', 'plt', 'pmt', 'poisson', 'polar', 'poly', 'poly1d', 'poly_below', 'poly_between', 'polyadd', 'polyder', 'polydiv', 'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'ppmt', 'prctile', 'prctile_rank', 'prepca', 'print_function', 'prism', 'prod', 'product', 'promote_types', 'psd', 'ptp', 'put', 'putmask', 'pv', 'pylab', 'pylab_setup', 'pyplot', 'qr', 'quit', 'quiver', 'quiverkey', 'r_', 'rad2deg', 'radians', 'rand', 'randint', 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rank', 'rate', 'ravel', 'ravel_multi_index', 'rayleigh', 'rc', 'rcParams', 'rcParamsDefault', 'rc_context', 'rcdefaults', 'real', 'real_if_close', 'rec', 'rec2csv', 'rec_append_fields', 'rec_drop_fields', 'rec_join', 'recarray', 'recfromcsv', 'recfromtxt', 'reciprocal', 'record', 'register_cmap', 'relativedelta', 'remainder', 'repeat', 'require', 'reshape', 'resize', 'restoredot', 'result_type', 'rfft', 'rfft2', 'rfftfreq', 'rfftn', 'rgrids', 'right_shift', 'rint', 'rk4', 'rms_flat', 'roll', 'rollaxis', 'roots', 'rot90', 'round_', 'row_stack', 'rrule', 's_', 'safe_eval', 'sample', 'sat', 'save', 'savefig', 'savetxt', 'savez', 'savez_compressed', 'sca', 'scatter', 'sci', 'sctype2char', 'sctypeDict', 'sctypeNA', 'sctypes', 'searchsorted', 'seed', 'segments_intersect', 'select', 'semilogx', 'semilogy', 'set_cmap', 'set_numeric_ops', 'set_printoptions', 'set_state', 'set_string_function', 'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj', 'setp', 'setxor1d', 'shape', 'short', 'show', 'show_config', 'shuffle', 'sign', 'signbit', 'signedinteger', 'silent_list', 'sin', 'sinc', 'single', 'singlecomplex', 'sinh', 'size', 'slogdet', 'slopes', 'solve', 'sometrue', 'sort', 'sort_complex', 'source', 'spacing', 'specgram', 'spectral', 'split', 'spring', 'spy', 'sqrt', 'square', 'squeeze', 'stackplot', 'standard_cauchy', 'standard_exponential', 'standard_gamma', 'standard_normal', 'standard_t', 'std', 'stem', 'step', 'stineman_interp', 'str_', 'streamplot', 'string0', 'string_', 'strpdate2num', 'subplot', 'subplot2grid', 'subplot_tool', 'subplots', 'subplots_adjust', 'subtract', 'sum', 'summer', 'sun', 'suptitle', 'svd', 'swapaxes', 'switch_backend', 'sys', 'table', 'take', 'tan', 'tanh', 'tensordot', 'tensorinv', 'tensorsolve', 'test', 'text', 'thetagrids', 'thu', 'tick_params', 'ticklabel_format', 'tight_layout', 'tile', 'timedelta64', 'title', 'trace', 'transpose', 'trapz', 'tri', 'triangular', 'tricontour', 'tricontourf', 'tril', 'tril_indices', 'tril_indices_from', 'trim_zeros', 'tripcolor', 'triplot', 'triu', 'triu_indices', 'triu_indices_from', 'true_divide', 'trunc', 'tue', 'twinx', 'twiny', 'typeDict', 'typeNA', 'typecodes', 'typename', 'ubyte', 'ufunc', 'uint', 'uint0', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'ulonglong', 'unicode0', 'unicode_', 'uniform', 'union1d', 'unique', 'unpackbits', 'unravel_index', 'unsignedinteger', 'unwrap', 'use_fastnumpy', 'ushort', 'vander', 'var', 'vdot', 'vector_lengths', 'vectorize', 'vlines', 'void', 'void0', 'vonmises', 'vsplit', 'vstack', 'waitforbuttonpress', 'wald', 'warnings', 'wed', 'weibull', 'where', 'who', 'window_hanning', 'window_none', 'winter', 'xcorr', 'xkcd', 'xlabel', 'xlim', 'xscale', 'xticks', 'ylabel', 'ylim', 'yscale', 'yticks', 'zeros', 'zeros_like', 'zipf']\n" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "a = 100\n", "print dir()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['ALLOW_THREADS', 'Annotation', 'Arrow', 'Artist', 'AutoLocator', 'Axes', 'BUFSIZE', 'Button', 'CLIP', 'Circle', 'ComplexWarning', 'DAILY', 'DataSource', 'DateFormatter', 'DateLocator', 'DayLocator', 'ERR_CALL', 'ERR_DEFAULT', 'ERR_DEFAULT2', 'ERR_IGNORE', 'ERR_LOG', 'ERR_PRINT', 'ERR_RAISE', 'ERR_WARN', 'FLOATING_POINT_SUPPORT', 'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW', 'FR', 'False_', 'Figure', 'FigureCanvasBase', 'FixedFormatter', 'FixedLocator', 'FormatStrFormatter', 'Formatter', 'FuncFormatter', 'GridSpec', 'HOURLY', 'HourLocator', 'In', 'IndexDateFormatter', 'IndexLocator', 'Inf', 'Infinity', 'LinAlgError', 'Line2D', 'LinearLocator', 'Locator', 'LogFormatter', 'LogFormatterExponent', 'LogFormatterMathtext', 'LogLocator', 'MAXDIMS', 'MINUTELY', 'MO', 'MONTHLY', 'MachAr', 'MaxNLocator', 'MinuteLocator', 'ModuleDeprecationWarning', 'MonthLocator', 'MultipleLocator', 'NAN', 'NINF', 'NZERO', 'NaN', 'Normalize', 'NullFormatter', 'NullLocator', 'Out', 'PINF', 'PZERO', 'PackageLoader', 'PolarAxes', 'Polygon', 'RAISE', 'RRuleLocator', 'RankWarning', 'Rectangle', 'SA', 'SECONDLY', 'SHIFT_DIVIDEBYZERO', 'SHIFT_INVALID', 'SHIFT_OVERFLOW', 'SHIFT_UNDERFLOW', 'SU', 'ScalarFormatter', 'ScalarType', 'SecondLocator', 'Slider', 'Subplot', 'SubplotTool', 'TH', 'TU', 'Tester', 'Text', 'TickHelper', 'True_', 'UFUNC_BUFSIZE_DEFAULT', 'UFUNC_PYVALS_NAME', 'WE', 'WEEKLY', 'WRAP', 'WeekdayLocator', 'Widget', 'YEARLY', 'YearLocator', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__name__', '__version__', '_dh', '_i', '_i1', '_i2', '_i3', '_i4', '_i5', '_ih', '_ii', '_iii', '_oh', '_sh', 'a', 'absolute', 'absolute_import', 'acorr', 'add', 'add_docstring', 'add_newdoc', 'add_newdoc_ufunc', 'add_newdocs', 'alen', 'all', 'allclose', 'alltrue', 'alterdot', 'amap', 'amax', 'amin', 'angle', 'annotate', 'any', 'append', 'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin', 'argpartition', 'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal', 'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrow', 'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray', 'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'autoscale', 'autumn', 'average', 'axes', 'axhline', 'axhspan', 'axis', 'axvline', 'axvspan', 'bar', 'barbs', 'barh', 'bartlett', 'base_repr', 'bench', 'beta', 'binary_repr', 'bincount', 'binomial', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'bivariate_normal', 'blackman', 'bmat', 'bone', 'bool8', 'bool_', 'box', 'boxplot', 'broadcast', 'broadcast_arrays', 'broken_barh', 'busday_count', 'busday_offset', 'busdaycalendar', 'byte', 'byte_bounds', 'bytes', 'bytes_', 'c_', 'can_cast', 'cast', 'cbook', 'cdouble', 'ceil', 'center_matrix', 'cfloat', 'char', 'character', 'chararray', 'chisquare', 'cholesky', 'choose', 'cla', 'clabel', 'clf', 'clim', 'clip', 'clongdouble', 'clongfloat', 'close', 'cm', 'cohere', 'colorbar', 'colormaps', 'colors', 'column_stack', 'common_type', 'compare_chararrays', 'complex128', 'complex256', 'complex64', 'complex_', 'complexfloating', 'compress', 'concatenate', 'cond', 'conj', 'conjugate', 'connect', 'contour', 'contourf', 'convolve', 'cool', 'copper', 'copy', 'copysign', 'copyto', 'corrcoef', 'correlate', 'cos', 'cosh', 'count_nonzero', 'cov', 'cross', 'csd', 'csingle', 'csv2rec', 'ctypeslib', 'cumprod', 'cumproduct', 'cumsum', 'date2num', 'datestr2num', 'datetime', 'datetime64', 'datetime_as_string', 'datetime_data', 'dedent', 'deg2rad', 'degrees', 'delaxes', 'delete', 'demean', 'deprecate', 'deprecate_with_doc', 'det', 'detrend', 'detrend_linear', 'detrend_mean', 'detrend_none', 'diag', 'diag_indices', 'diag_indices_from', 'diagflat', 'diagonal', 'diff', 'digitize', 'disconnect', 'disp', 'display', 'dist', 'dist_point_to_segment', 'distances_along_curve', 'divide', 'division', 'docstring', 'dot', 'double', 'drange', 'draw', 'draw_if_interactive', 'dsplit', 'dstack', 'dtype', 'e', 'ediff1d', 'eig', 'eigh', 'eigvals', 'eigvalsh', 'einsum', 'emath', 'empty', 'empty_like', 'entropy', 'epoch2num', 'equal', 'errorbar', 'errstate', 'euler_gamma', 'eventplot', 'exception_to_str', 'exit', 'exp', 'exp2', 'exp_safe', 'expand_dims', 'expm1', 'exponential', 'extract', 'eye', 'f', 'fabs', 'fastCopyAndTranspose', 'fft', 'fft2', 'fftfreq', 'fftn', 'fftpack', 'fftpack_lite', 'fftshift', 'fftsurr', 'figaspect', 'figimage', 'figlegend', 'fignum_exists', 'figsize', 'figtext', 'figure', 'fill', 'fill_between', 'fill_betweenx', 'fill_diagonal', 'find', 'find_common_type', 'findobj', 'finfo', 'fix', 'flag', 'flatiter', 'flatnonzero', 'flatten', 'flexible', 'fliplr', 'flipud', 'float128', 'float16', 'float32', 'float64', 'float_', 'floating', 'floor', 'floor_divide', 'fmax', 'fmin', 'fmod', 'format_parser', 'frange', 'frexp', 'fri', 'frombuffer', 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromregex', 'fromstring', 'full', 'full_like', 'fv', 'gamma', 'gca', 'gcf', 'gci', 'generic', 'genfromtxt', 'geometric', 'get', 'get_array_wrap', 'get_backend', 'get_cmap', 'get_current_fig_manager', 'get_figlabels', 'get_fignums', 'get_include', 'get_ipython', 'get_numarray_include', 'get_plot_commands', 'get_printoptions', 'get_scale_docs', 'get_scale_names', 'get_sparse_matrix', 'get_state', 'get_xyz_where', 'getbuffer', 'getbufsize', 'geterr', 'geterrcall', 'geterrobj', 'getfigs', 'getp', 'ginput', 'gradient', 'gray', 'greater', 'greater_equal', 'grid', 'griddata', 'gumbel', 'half', 'hamming', 'hanning', 'helper', 'hexbin', 'hfft', 'hist', 'hist2d', 'histogram', 'histogram2d', 'histogramdd', 'hlines', 'hold', 'hot', 'hsplit', 'hstack', 'hsv', 'hypergeometric', 'hypot', 'i0', 'identity', 'ifft', 'ifft2', 'ifftn', 'ifftshift', 'ihfft', 'iinfo', 'imag', 'imread', 'imsave', 'imshow', 'in1d', 'index_exp', 'indices', 'inexact', 'inf', 'info', 'infty', 'inner', 'insert', 'inside_poly', 'int0', 'int16', 'int32', 'int64', 'int8', 'int_', 'int_asbuffer', 'intc', 'integer', 'interactive', 'interp', 'intersect1d', 'intp', 'inv', 'invert', 'ioff', 'ion', 'ipmt', 'irfft', 'irfft2', 'irfftn', 'irr', 'is_busday', 'is_closed_polygon', 'is_numlike', 'is_string_like', 'isclose', 'iscomplex', 'iscomplexobj', 'isfinite', 'isfortran', 'ishold', 'isinf', 'isinteractive', 'isnan', 'isneginf', 'isposinf', 'ispower2', 'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_', 'issubdtype', 'issubsctype', 'isvector', 'iterable', 'ix_', 'jet', 'kaiser', 'kron', 'l1norm', 'l2norm', 'lapack_lite', 'laplace', 'ldexp', 'left_shift', 'legend', 'less', 'less_equal', 'levypdf', 'lexsort', 'linalg', 'linspace', 'little_endian', 'load', 'loads', 'loadtxt', 'locator_params', 'log', 'log10', 'log1p', 'log2', 'logaddexp', 'logaddexp2', 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logistic', 'loglog', 'lognormal', 'logseries', 'logspace', 'longcomplex', 'longdouble', 'longest_contiguous_ones', 'longest_ones', 'longfloat', 'longlong', 'lookfor', 'lstsq', 'ma', 'mafromtxt', 'margins', 'mask_indices', 'mat', 'math', 'matplotlib', 'matrix', 'matrix_power', 'matrix_rank', 'matshow', 'maximum', 'maximum_sctype', 'may_share_memory', 'mean', 'median', 'memmap', 'meshgrid', 'mgrid', 'min_scalar_type', 'minimum', 'minorticks_off', 'minorticks_on', 'mintypecode', 'mirr', 'mlab', 'mod', 'modf', 'mon', 'movavg', 'mpl', 'msort', 'multinomial', 'multiply', 'multivariate_normal', 'mx2num', 'nan', 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmean', 'nanmin', 'nanstd', 'nansum', 'nanvar', 'nbytes', 'ndarray', 'ndenumerate', 'ndfromtxt', 'ndim', 'ndindex', 'nditer', 'negative', 'negative_binomial', 'nested_iters', 'new_figure_manager', 'newaxis', 'newbuffer', 'nextafter', 'noncentral_chisquare', 'noncentral_f', 'nonzero', 'norm', 'norm_flat', 'normal', 'normalize', 'normpdf', 'not_equal', 'np', 'nper', 'npv', 'num2date', 'num2epoch', 'number', 'numpy', 'obj2sctype', 'object0', 'object_', 'ogrid', 'ones', 'ones_like', 'outer', 'over', 'packbits', 'pad', 'pareto', 'partition', 'path_length', 'pause', 'pcolor', 'pcolormesh', 'percentile', 'permutation', 'pi', 'pie', 'piecewise', 'pink', 'pinv', 'pkgload', 'place', 'plot', 'plot_date', 'plotfile', 'plotting', 'plt', 'pmt', 'poisson', 'polar', 'poly', 'poly1d', 'poly_below', 'poly_between', 'polyadd', 'polyder', 'polydiv', 'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'ppmt', 'prctile', 'prctile_rank', 'prepca', 'print_function', 'prism', 'prod', 'product', 'promote_types', 'psd', 'ptp', 'put', 'putmask', 'pv', 'pylab', 'pylab_setup', 'pyplot', 'qr', 'quit', 'quiver', 'quiverkey', 'r_', 'rad2deg', 'radians', 'rand', 'randint', 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rank', 'rate', 'ravel', 'ravel_multi_index', 'rayleigh', 'rc', 'rcParams', 'rcParamsDefault', 'rc_context', 'rcdefaults', 'real', 'real_if_close', 'rec', 'rec2csv', 'rec_append_fields', 'rec_drop_fields', 'rec_join', 'recarray', 'recfromcsv', 'recfromtxt', 'reciprocal', 'record', 'register_cmap', 'relativedelta', 'remainder', 'repeat', 'require', 'reshape', 'resize', 'restoredot', 'result_type', 'rfft', 'rfft2', 'rfftfreq', 'rfftn', 'rgrids', 'right_shift', 'rint', 'rk4', 'rms_flat', 'roll', 'rollaxis', 'roots', 'rot90', 'round_', 'row_stack', 'rrule', 's_', 'safe_eval', 'sample', 'sat', 'save', 'savefig', 'savetxt', 'savez', 'savez_compressed', 'sca', 'scatter', 'sci', 'sctype2char', 'sctypeDict', 'sctypeNA', 'sctypes', 'searchsorted', 'seed', 'segments_intersect', 'select', 'semilogx', 'semilogy', 'set_cmap', 'set_numeric_ops', 'set_printoptions', 'set_state', 'set_string_function', 'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj', 'setp', 'setxor1d', 'shape', 'short', 'show', 'show_config', 'shuffle', 'sign', 'signbit', 'signedinteger', 'silent_list', 'sin', 'sinc', 'single', 'singlecomplex', 'sinh', 'size', 'slogdet', 'slopes', 'solve', 'sometrue', 'sort', 'sort_complex', 'source', 'spacing', 'specgram', 'spectral', 'split', 'spring', 'spy', 'sqrt', 'square', 'squeeze', 'stackplot', 'standard_cauchy', 'standard_exponential', 'standard_gamma', 'standard_normal', 'standard_t', 'std', 'stem', 'step', 'stineman_interp', 'str_', 'streamplot', 'string0', 'string_', 'strpdate2num', 'subplot', 'subplot2grid', 'subplot_tool', 'subplots', 'subplots_adjust', 'subtract', 'sum', 'summer', 'sun', 'suptitle', 'svd', 'swapaxes', 'switch_backend', 'sys', 'table', 'take', 'tan', 'tanh', 'tensordot', 'tensorinv', 'tensorsolve', 'test', 'text', 'thetagrids', 'thu', 'tick_params', 'ticklabel_format', 'tight_layout', 'tile', 'timedelta64', 'title', 'trace', 'transpose', 'trapz', 'tri', 'triangular', 'tricontour', 'tricontourf', 'tril', 'tril_indices', 'tril_indices_from', 'trim_zeros', 'tripcolor', 'triplot', 'triu', 'triu_indices', 'triu_indices_from', 'true_divide', 'trunc', 'tue', 'twinx', 'twiny', 'typeDict', 'typeNA', 'typecodes', 'typename', 'ubyte', 'ufunc', 'uint', 'uint0', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'ulonglong', 'unicode0', 'unicode_', 'uniform', 'union1d', 'unique', 'unpackbits', 'unravel_index', 'unsignedinteger', 'unwrap', 'use_fastnumpy', 'ushort', 'vander', 'var', 'vdot', 'vector_lengths', 'vectorize', 'vlines', 'void', 'void0', 'vonmises', 'vsplit', 'vstack', 'waitforbuttonpress', 'wald', 'warnings', 'wed', 'weibull', 'where', 'who', 'window_hanning', 'window_none', 'winter', 'xcorr', 'xkcd', 'xlabel', 'xlim', 'xscale', 'xticks', 'ylabel', 'ylim', 'yscale', 'yticks', 'zeros', 'zeros_like', 'zipf']\n" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ud2b9\ubcc4 \uc18d\uc131: \ud30c\uc774\uc36c \ub0b4\uc5d0 \uc874\uc7ac\ud558\ub294 \ubaa8\ub4e0 \uac1d\uccb4 \ub9c8\ub2e4 \ubd80\uc5ec\ub418\ub294 \ud2b9\ubcc4\ud55c Read-only \uc18d\uc131\n", " - [\ucc38\uace0]: https://docs.python.org/2/library/stdtypes.html#object.__dict__" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"name: \" # \ub85c\uceec \uc774\ub984\n", "print __name__\n", "print\n", "\n", "print \"doc: \" # \ub85c\uceec\uc5d0 \uc9c0\uc815\ub41c \ubb38\uc11c\ubb38\uc790\uc5f4 \n", "print __doc__\n", "print" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "name: \n", "__main__\n", "\n", "doc: \n", "Automatically created module for IPython interactive environment\n", "\n" ] } ], "prompt_number": 31 }, { "cell_type": "code", "collapsed": false, "input": [ "import math\n", "\n", "print \"math.__name__: \", math.__name__\n", "print\n", "print dir(math) # dir() \ub0b4\uc7a5 \ud568\uc218\uc5d0 \ubaa8\ub4c8\uc744 \uc778\uc790\ub85c \uc804\ub2ec\ud558\uba74 \ud574\ub2f9 \ubaa8\ub4c8\uc774 \uc9c0\uc6d0\ud558\ub294 \uba64\ubc84 \ubcc0\uc218 \ubc0f \ud568\uc218 \ubaa9\ub85d\uc744 \uc5bb\ub294\ub2e4.\n", "print\n", "print \"math.__doc__:\", math.__doc__\n", "print\n", "print \"math.log10.__doc__: \", math.log10.__doc__" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "math.__name__: math\n", "\n", "['__doc__', '__file__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']\n", "\n", "math.__doc__: This module is always available. It provides access to the\n", "mathematical functions defined by the C standard.\n", "\n", "math.log10.__doc__: log10(x)\n", "\n", "Return the base 10 logarithm of x.\n" ] } ], "prompt_number": 32 }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "print dir(sys) # dir() \ub0b4\uc7a5 \ud568\uc218\uc5d0 \ubaa8\ub4c8\uc744 \uc778\uc790\ub85c \uc804\ub2ec\ud558\uba74 \ud574\ub2f9 \ubaa8\ub4c8\uc774 \uc9c0\uc6d0\ud558\ub294 \uba64\ubc84 \ubcc0\uc218 \ubc0f \ud568\uc218 \ubaa9\ub85d\uc744 \uc5bb\ub294\ub2e4." ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_executable', '_getframe', '_home', '_mercurial', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'ps3', 'py3kwarning', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']\n" ] } ], "prompt_number": 34 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 10 \uba85\ub839\ud589 \uc778\uc218 \ucc98\ub9ac\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 10-1 \uba85\ub839\ud589 \uc778\uc218 \uc5bb\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# file: arg.py\n", "import sys\n", "print sys.argv" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "# python arg.py -l -a -v a b c" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 10-2 \uba85\ub839\ud589 \uc635\uc158 \ucc98\ub9ac\n", "- getopt \ubaa8\ub4c8\uc758 getopt() \ud568\uc218\uc758 \ub450 \uac1c \uc778\uc790\n", " - \uccab\ubc88\uc9f8 \uc778\uc790: \ub300\ubd80\ubd84\uc758 \uacbd\uc6b0 sys.argv[1:] \ub97c \ub123\uc5b4 \uc900\ub2e4.\n", " - \ub450\ubc88\uc9f8 \uc778\uc790: \uc628\uc158 \ubb38\uc790\ub97c \ud3ec\ud568\ud55c \ubb38\uc790\uc5f4\n", "- ipython \uc5d0\uc11c\ub294 getopt \ubaa8\ub4c8 \ubcf4\ub2e4 argparse \ubaa8\ub4c8\uc744 \ub354 \ucd94\ucc9c\ud55c\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import getopt\n", "argv = '-a -b -c123 -d 456 spam and ham' #\uac00\uc0c1\uc73c\ub85c \ub9cc\ub4e0 sys.argv\ub85c \ubc1b\uc740 \uba85\ub839\ud589 \uc635\uc158 \ubb38\uc790\uc5f4\n", "#argv = sys.argv[1:] <-- \uc2e4\uc81c\ub85c \ub9cc\ub4dc\ub294 \ubc29\ubc95\n", "args = argv.split() # \uacf5\ubc31\uc73c\ub85c \ubd84\ub9ac \ubc0f \uac04 \ub2e8\uc5b4\ub97c \uc9c0\ub2cc \ub9ac\uc2a4\ud2b8 \uc0dd\uc131 \n", "print args\n", "print\n", "\n", "optlist, args = getopt.getopt(args, 'abc:d:') # a, b\ub294 \ucd94\uac00 \uc778\uc218\uac00 \uc5c6\uc74c\uc744 \ub098\ud0c0\ub0c4\n", "print optlist # c:, d:\ub294 \ucd94\uac00 \uc778\uc218\uac00 \uc874\uc7ac\ud568\uc744 \ub098\ud0c0\ub0c4 \n", "print args # \uc635\uc158\uc744 \ucc98\ub9ac\ud558\uace0 \ub0a8\uc544\uc788\ub294 \uba85\ub839\ud589 \uc778\uc218\ub4e4" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['-a', '-b', '-c123', '-d', '456', 'spam', 'and', 'ham']\n", "\n", "[('-a', ''), ('-b', ''), ('-c', '123'), ('-d', '456')]\n", "['spam', 'and', 'ham']\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 11 \ubc30\uc5f4 \ud45c\ud604\ud558\uae30\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 11-1 \ub9ac\uc2a4\ud2b8\ub85c 1\ucc28\uc6d0 \ubc30\uc5f4 \ud45c\ud604\ud558\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [1, 2, 3, 4, 5]\n", "b = range(10)\n", "print a\n", "print b" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[1, 2, 3, 4, 5]\n", "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n" ] } ], "prompt_number": 16 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- 0\uc73c\ub85c \ucd08\uae30\ud654\ub41c \uc0ac\uc774\uc988 10\uc778 1\ucc28\uc6d0 \ubc30\uc5f4 \uc0dd\uc131\n", " - \ubc18\ubcf5(\\*) \uc5f0\uc0b0\uc774 \uc218\uce58\uac12\uc5d0 \uc801\uc6a9\ub418\uba74 \uc218\uce58\uac12\uc774 \uc0c8\ub86d\uac8c \ub9cc\ub4e4\uc5b4\uc9c0\uba74\uc11c \ubc30\uc5f4\uc744 \uc0dd\uc131" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = [0] * 10\n", "a" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 17, "text": [ "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]" ] } ], "prompt_number": 17 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 11-2 \ub0b4\uc6a9\uc5c6\ub294 \ub9ac\uc2a4\ud2b8 \ubbf8\ub9ac \uc0dd\uc131\ud558\uae30\n", "- \ub0b4\uc6a9\uc774 \uc5c6\uc74c\uc740 None \uac12 \ud560\ub2f9 \ucd94\ucc9c\n", " - \uc218\uce58\ub9cc\uc744 \uc800\uc7a5\ud560 \ub54c\uc5d0\ub294 0 \uc774\ub098 0.0\uc73c\ub85c \ucd08\uae30\ud654 \ubc29\ubc95\ub3c4 \uc88b\uc74c\n", "- \ubbf8\ub9ac \ub9ac\uc2a4\ud2b8\ub97c \uc0dd\uc131\ud558\uace0 \ud544\uc694\ud55c \uc6d0\uc18c\uc5d0 \ub0b4\uc6a9 \ucc44\uc6c0" ] }, { "cell_type": "code", "collapsed": false, "input": [ "N = [20, 15, 39, 2, 7, 5, 223, 75, 46, 87]\n", "M = [3, 5, 9, 2, 7]\n", "L = [None] * 10\n", "for k in M:\n", " L[k] = k * N[k]\n", "print L" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[None, None, 78, 6, None, 25, None, 525, None, 783]\n" ] } ], "prompt_number": 19 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 11-3 \ub9ac\uc2a4\ud2b8\ub85c 2\ucc28\uc6d0 \ubc30\uc5f4(\ud589\ub82c)\ud45c\ud604\ud558\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "mat = [ [1, 2, 3],\n", " [4, 5, 6],\n", " [7, 8, 9] ]\n", "print mat\n", "print mat[1][2]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", "6\n" ] } ], "prompt_number": 20 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- [\uc8fc\uc758] \ub2e4\uc74c \ubc29\ubc95\uc73c\ub85c 2\ucc28\uc6d0 \ubc30\uc5f4 \uc0dd\uc131\ud558\uba74 \uc548\ub428\n", " - \ubc18\ubcf5(*) \uc5f0\uc0b0\uc774 \ub9ac\uc2a4\ud2b8 \uac1d\uccb4\uc5d0 \ub300\ud574\uc11c\ub294 \ud574\ub2f9 \ub9ac\uc2a4\ud2b8 \uac1d\uccb4\uc758 \ub808\ud37c\ub7f0\uc2a4\ub97c \ubcf5\uc0ac\ud558\uae30 \ub54c\ubb38" ] }, { "cell_type": "code", "collapsed": false, "input": [ "mat = [[0] * 4] * 3\n", "mat" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 25, "text": [ "[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]" ] } ], "prompt_number": 25 }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](images/2d_array.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \uc704\uc5d0\uc11c \uc138 \uac1c\uc758 \ud589\uc740 \ub3d9\uc77c\ud55c \uac1d\uccb4\uc784" ] }, { "cell_type": "code", "collapsed": false, "input": [ "mat[0][0] = 100\n", "mat" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 26, "text": [ "[[100, 0, 0, 0], [100, 0, 0, 0], [100, 0, 0, 0]]" ] } ], "prompt_number": 26 }, { "cell_type": "markdown", "metadata": {}, "source": [ "- for \ubb38\uc744 \ud65c\uc6a9\ud55c 2\ucc28\uc6d0 \ubc30\uc5f4\uc758 \uc62c\ubc14\ub978 \uc0dd\uc131 \ubc29\ubc95" ] }, { "cell_type": "code", "collapsed": false, "input": [ "mat = []\n", "for x in range(3):\n", " mat.append( [0] * 4)\n", " \n", "print mat\n", "\n", "mat[0][0] = 100\n", "print mat" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n", "[[100, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n" ] } ], "prompt_number": 25 }, { "cell_type": "markdown", "metadata": {}, "source": [ "![image](images/2d_array2.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- \ub9ac\uc2a4\ud2b8 \ub0b4\ud3ec \ud65c\uc6a9" ] }, { "cell_type": "code", "collapsed": false, "input": [ "mat = [ [0]*4 for x in range(3)]\n", "print mat\n", "\n", "mat[0][0] = 100\n", "print mat" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n", "[[100, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]\n" ] } ], "prompt_number": 27 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 11-4 array \ubaa8\ub4c8 \uc774\uc6a9\ud558\uae30" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- array \ubaa8\ub4c8: \ub3d9\uc77c \uc790\ub8cc\ud615\uc744 \uc9c0\ub2cc \uac01 \uc6d0\uc18c\uc5d0 \ub300\ud55c \ubc30\uc5f4 \uc0dd\uc131\uc744 \uc704\ud574 \uc0ac\uc6a9\ud558\ub294 \ubaa8\ub4c8\n", "- array(typecode [, initializer])\n", " - typecode: \ubc30\uc5f4 \ub0b4 \uc6d0\uc18c\uc5d0 \ub300\ud55c \uc790\ub8cc\ud615\n", " - initializer: \ub9ac\uc2a4\ud2b8 \ub610\ub294 \ub9ac\uc2a4\ud2b8\ub97c \uc0dd\uc131\ud558\ub294 \ubb38\uc790\uc5f4\n", " - [\ucc38\uace0] https://docs.python.org/2/library/array.html\n", "- [\uc8fc\uc758] 1\ucc28\uc6d0 \ubc30\uc5f4 \uc0dd\uc131\ub9cc \uac00\ub2a5\n", "- list \ub300\uc2e0\uc5d0 array \uc0ac\uc6a9\ud574\uc57c \ud560 \ub54c\n", " - \uc880 \ub354 compact\ud558\uac8c \uba54\ubaa8\ub9ac\uc5d0 \uc790\ub8cc\ub97c \uc720\uc9c0\ud558\uace0 \uc2f6\uc744 \ub54c\n", " - [\ucc38\uace0] http://stackoverflow.com/questions/176011/python-list-vs-array-when-to-use" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 1) \ucd08\uae30 \uac12\uc73c\ub85c \uc0dd\uc131\ud558\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from array import *\n", "a = array('i')\n", "print a\n", "\n", "a = array('i', range(10))\n", "print a\n", "\n", "a = array('i', [0] * 10)\n", "print a\n", "\n", "b = array('c', \"Hello Python\")\n", "print b\n", "print b[0], b[1]" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "array('i')\n", "array('i', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n", "array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n", "array('c', 'Hello Python')\n", "H e\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 2) \ub3d9\uc801\uc73c\ub85c \uc0dd\uc131\ud558\uae30\n", "- \ub9ac\uc2a4\ud2b8\uc640 \uac19\uc774 append, insert, extend \uba54\uc3d8\ub4dc\ub97c \uc774\uc6a9\ud55c\ub2e4." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from array import *\n", "\n", "a = array('i')\n", "a.append(1)\n", "a.append(4)\n", "print a\n", "\n", "a.insert(1,2) # \uc778\ub371\uc2a4 1 \uc704\uce58\uc5d0 2 \uac12 \ub123\uae30\n", "print a\n", "\n", "a.extend(array('i', [1, 2, 3, 4, 5]))\n", "print a" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "array('i', [1, 4])\n", "array('i', [1, 2, 4])\n", "array('i', [1, 2, 4, 1, 2, 3, 4, 5])\n" ] } ], "prompt_number": 38 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 3) \ubc30\uc5f4 \ucc38\uc870" ] }, { "cell_type": "code", "collapsed": false, "input": [ "a = array('i', [1, 2, 3, 4, 5])\n", "print a[0]\n", "print a[-1]\n", "print a[1:3]\n", "print a[1:-1]\n", "print\n", "\n", "del a[0]\n", "print a\n", "print\n", "\n", "del a[:3]\n", "print a\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n", "5\n", "array('i', [2, 3])\n", "array('i', [2, 3, 4])\n", "\n", "array('i', [2, 3, 4, 5])\n", "\n", "array('i', [5])\n" ] } ], "prompt_number": 41 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### [\ucc38\uace0] Numpy\ub97c \uc774\uc6a9\ud55c \ubc30\uc5f4 \ud45c\ud604\n", "- \uc5ec\ub7ec \ud615\ud0dc\uc758 \ubc30\uc5f4\uc5d0 \ub300\ud574 \uc0b0\uc220 \uc5f0\uc0b0\uc774 \ud544\uc694\ud558\uba74 array \ubaa8\ub4c8\ubcf4\ub2e4 Numpy \ubaa8\ub4c8 \ud65c\uc6a9 \ucd94\ucc9c\n", "- Numpy \ubaa8\ub4c8: \uc120\ud615\ub300\uc218\uc5d0 \uad00\ud55c \uac01\uc885 \uc218\ud559\uc801 \uc5f0\uc0b0\uc744 \ud6a8\uacfc\uc801\uc73c\ub85c \uc9c0\uc6d0" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from numpy import *\n", "a = array(((1,2,3), (4,5,6), (7, 8, 9))) # 3*3 \ud589\ub82c \uc0dd\uc131\n", "print a\n", "print\n", "\n", "b = zeros((3,3))\n", "print b\n", "print\n", "\n", "c = ones((3,3))\n", "print c\n", "print\n", "\n", "d = a * c\n", "print d\n", "print\n", "\n", "e = dot(a, c)\n", "print e\n", "print\n", "\n", "f = a + c\n", "print f\n", "print\n", "\n", "from numpy.linalg import *\n", "g = inv(a)\n", "print g\n", "print\n", "\n", "h = eig(a)\n", "print h\n", "print" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[[1 2 3]\n", " [4 5 6]\n", " [7 8 9]]\n", "\n", "[[ 0. 0. 0.]\n", " [ 0. 0. 0.]\n", " [ 0. 0. 0.]]\n", "\n", "[[ 1. 1. 1.]\n", " [ 1. 1. 1.]\n", " [ 1. 1. 1.]]\n", "\n", "[[ 1. 2. 3.]\n", " [ 4. 5. 6.]\n", " [ 7. 8. 9.]]\n", "\n", "[[ 6. 6. 6.]\n", " [ 15. 15. 15.]\n", " [ 24. 24. 24.]]\n", "\n", "[[ 2. 3. 4.]\n", " [ 5. 6. 7.]\n", " [ 8. 9. 10.]]\n", "\n", "[[ -4.50359963e+15 9.00719925e+15 -4.50359963e+15]\n", " [ 9.00719925e+15 -1.80143985e+16 9.00719925e+15]\n", " [ -4.50359963e+15 9.00719925e+15 -4.50359963e+15]]\n", "\n", "(array([ 1.61168440e+01, -1.11684397e+00, -1.30367773e-15]), array([[-0.23197069, -0.78583024, 0.40824829],\n", " [-0.52532209, -0.08675134, -0.81649658],\n", " [-0.8186735 , 0.61232756, 0.40824829]]))\n", "\n" ] } ], "prompt_number": 65 }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "## 12 \ub514\ub809\ud1a0\ub9ac \ud30c\uc77c \ubaa9\ub85d \uc5bb\uae30\n", "***\n", "- glob \ubaa8\ub4c8\uc758 glob \ud568\uc218: \ub514\ub809\ud1a0\ub9ac\uc758 \ud30c\uc77c \ubaa9\ub85d\uc744 \uc5bb\uc5b4\uc624\ub294 \ud568\uc218\n", " - ?: \uc784\uc758\uc758 \ubb38\uc790 1\uac1c\uc640 \ub9e4\uce6d\n", " - *: 0\uac1c \uc774\uc0c1\uc758 \ubaa8\ub4e0 \ubb38\uc790\uc640 \ub9e4\uce6d\n", " - [..]: \uad04\ud638 \uc548\uc758 \uc784\uc758\uc758 1\uac1c \ubb38\uc790\uc640 \ub9e4\uce6d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 12-1 \ubaa9\ub85d \uc5bb\uae30" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import glob\n", "print glob.glob('./[0-9].*')\n", "print glob.glob('*.gif')\n", "print glob.glob('?.gif')\n", "print glob.glob('*.ipynb')\n", "print glob.glob('*.i*')\n", "print glob.glob('*')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[]\n", "[]\n", "[]\n", "['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'Untitled0.ipynb']\n", "['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'Untitled0.ipynb']\n", "['assignment-1.ipynb', 'assignment-2.ipynb', 'cal.ipynb', 'cal.py', 'docstring.py', 'docstring.pyc', 'getopt_test.py', 'images', 'modfile.py', 'modfile.pyc', 'python01.ipynb', 'python02.ipynb', 'python03.ipynb', 'python04.ipynb', 'python05.ipynb', 'python06.ipynb', 'python07.ipynb', 'python08.ipynb', 'README.md', 'Untitled0.ipynb']\n" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 12-2 \ud30c\uc77c\uc758 \ucd94\uac00 \uc815\ubcf4 \uc54c\uc544\ub0b4\uae30\n", "- os \ubaa8\ub4c8\uc758 \uc11c\ube0c\ubaa8\ub4c8\uc778 path \ubaa8\ub4c8 \ud65c\uc6a9" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import glob\n", "import os\n", "flist = glob.glob('*')\n", "for fname in flist:\n", " \n", " if os.path.isfile(fname):\n", " print fname, 'is a regular file.'\n", " \n", " elif os.path.isdir(fname):\n", " print fname, 'is a dir'\n", " \n", " elif os.path.islink(fname):\n", " print fname, 'is a symbolic link'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "assignment-1.ipynb is a regular file.\n", "assignment-2.ipynb is a regular file.\n", "cal.ipynb is a regular file.\n", "cal.py is a regular file.\n", "docstring.py is a regular file.\n", "docstring.pyc is a regular file.\n", "getopt_test.py is a regular file.\n", "images is a dir\n", "modfile.py is a regular file.\n", "modfile.pyc is a regular file.\n", "python01.ipynb is a regular file.\n", "python02.ipynb is a regular file.\n", "python03.ipynb is a regular file.\n", "python04.ipynb is a regular file.\n", "python05.ipynb is a regular file.\n", "python06.ipynb is a regular file.\n", "python07.ipynb is a regular file.\n", "python08.ipynb is a regular file.\n", "README.md is a regular file.\n", "Untitled0.ipynb is a regular file.\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "print os.path.getsize('python05.ipynb') # \ud30c\uc77c\uc758 \ud06c\uae30\ub97c \uc5bb\ub294\ub2e4.\n", "\n", "t = os.path.getatime('python05.ipynb') # \ud30c\uc77c\uc758 \ucd5c\uc885 \uc811\uadfc\uc2dc\uac04\uc744 \uc5bb\ub294\ub2e4. \n", "print t # \ub9ac\ud134\ub41c \uc2dc\uac04\uc740 1970\ub144 1\uc6d4 1\uc77c 00\uc2dc 00\ubd84 \ubd80\ud130 \uacbd\uacfc\ud55c \ucd08 \n", "\n", "import time\n", "\n", "print time.ctime(t) # \ubb38\uc790\uc5f4 \uc2dc\uac04\uc73c\ub85c \ubcc0\ud658\n", "print time.ctime(os.path.getmtime('python05.ipynb')) # \ud30c\uc77c\uc758 \ucd5c\uc885 \uc218\uc815\uc2dc\uac04\uc744 \uc5bb\ub294\ub2e4 (\uac00\uc7a5 \ub9ce\uc774 \uc0ac\uc6a9)\n", "print time.ctime(os.path.getctime('python05.ipynb')) # \ud30c\uc77c\uc758 \uc0dd\uc131 \uc2dc\uac04\uc744 \uc5bb\ub294\ub2e4 (\ub300\ubd80\ubd84\uc758 \uacbd\uc6b0 getmtime()\uacfc \ub3d9\uc77c)." ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "96388\n", "1411980452.0\n", "Mon Sep 29 17:47:32 2014\n", "Mon Sep 29 17:48:24 2014\n", "Mon Sep 29 17:48:24 2014\n" ] } ], "prompt_number": 17 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }