From 2e84e20cb3f527f3ace21b4940e3785e8d971c7f Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Thu, 22 Dec 2016 19:48:38 -0500 Subject: [PATCH 1/6] This is my initial commit of creating a repo --- README.md | 2 ++ Welcome to the Course.ipynb | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 README.md create mode 100644 Welcome to the Course.ipynb diff --git a/README.md b/README.md new file mode 100644 index 0000000..6edeead --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Python-Data-Science-and-Machine-Learning-Bootcamp +Repo for Python Data Science and Machine Learning Bootcamp diff --git a/Welcome to the Course.ipynb b/Welcome to the Course.ipynb new file mode 100644 index 0000000..4ccc1c4 --- /dev/null +++ b/Welcome to the Course.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Welcome to the Course \n", + "\n", + "This is the repository for the course: **Python Data Science and Machine Learning Bootcamp**\n", + "\n", + "Thank you so much for enrolling in the course!\n", + "\n", + "## Overview of this Repository\n", + "\n", + "This repository contains everything you need for the course, it has all the notebooks, links" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "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.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 32a6ac2f7d130aa69cccd2d92375bc0b87170342 Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Thu, 22 Dec 2016 19:50:14 -0500 Subject: [PATCH 2/6] Modified Readme.md file --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6edeead..82fd080 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Python-Data-Science-and-Machine-Learning-Bootcamp Repo for Python Data Science and Machine Learning Bootcamp +This is a test to make some changes From e492ea8a6c079fd557e2ae6a5742c4f30343f8dd Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Thu, 22 Dec 2016 20:06:01 -0500 Subject: [PATCH 3/6] set up Jupyter Notebook and ready to roll --- 00_Setup/.ipynb_checkpoints/Setup-checkpoint.ipynb | 6 ++++++ 00_Setup/Setup.ipynb | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 00_Setup/.ipynb_checkpoints/Setup-checkpoint.ipynb create mode 100644 00_Setup/Setup.ipynb diff --git a/00_Setup/.ipynb_checkpoints/Setup-checkpoint.ipynb b/00_Setup/.ipynb_checkpoints/Setup-checkpoint.ipynb new file mode 100644 index 0000000..59ce53d --- /dev/null +++ b/00_Setup/.ipynb_checkpoints/Setup-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/00_Setup/Setup.ipynb b/00_Setup/Setup.ipynb new file mode 100644 index 0000000..59ce53d --- /dev/null +++ b/00_Setup/Setup.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 1 +} From 14ac08bf8eb66fb497a3255c616980241904e882 Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Thu, 22 Dec 2016 20:33:03 -0500 Subject: [PATCH 4/6] Python Crash Course Course 1 --- .../01_PythonCrashCourse-checkpoint.ipynb | 76 +++++++++++++++++++ .../01_PythonCrashCourse.ipynb | 76 +++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb create mode 100644 01_PythonCrashCourse/01_PythonCrashCourse.ipynb diff --git a/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb b/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb new file mode 100644 index 0000000..1e8e7d4 --- /dev/null +++ b/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb @@ -0,0 +1,76 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1+2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print (1+2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/01_PythonCrashCourse/01_PythonCrashCourse.ipynb b/01_PythonCrashCourse/01_PythonCrashCourse.ipynb new file mode 100644 index 0000000..1e8e7d4 --- /dev/null +++ b/01_PythonCrashCourse/01_PythonCrashCourse.ipynb @@ -0,0 +1,76 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1+2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print (1+2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [conda root]", + "language": "python", + "name": "conda-root-py" + }, + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} From 2067e507a20fa3c5d3c61c51213937eb7f61f514 Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Thu, 22 Dec 2016 20:36:00 -0500 Subject: [PATCH 5/6] another small modification --- .../01_PythonCrashCourse-checkpoint.ipynb | 22 +++++++++++++++++++ .../01_PythonCrashCourse.ipynb | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb b/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb index 1e8e7d4..1d8d78a 100644 --- a/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb +++ b/01_PythonCrashCourse/.ipynb_checkpoints/01_PythonCrashCourse-checkpoint.ipynb @@ -41,6 +41,28 @@ "print (1+2)" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 / 2" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/01_PythonCrashCourse/01_PythonCrashCourse.ipynb b/01_PythonCrashCourse/01_PythonCrashCourse.ipynb index 1e8e7d4..1d8d78a 100644 --- a/01_PythonCrashCourse/01_PythonCrashCourse.ipynb +++ b/01_PythonCrashCourse/01_PythonCrashCourse.ipynb @@ -41,6 +41,28 @@ "print (1+2)" ] }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 / 2" + ] + }, { "cell_type": "code", "execution_count": null, From b0f92a8af49808508f7436788cd96d679ca86cf8 Mon Sep 17 00:00:00 2001 From: Isaac Zhou Date: Fri, 23 Dec 2016 01:13:23 -0500 Subject: [PATCH 6/6] Adding all exercise files --- ...n Crash Course Exercises - Solutions.ipynb | 522 ++++ .../Python Crash Course Exercises .ipynb | 484 ++++ .../Python Crash Course.ipynb | 2220 +++++++++++++++++ 3 files changed, 3226 insertions(+) create mode 100644 01_PythonCrashCourse/Python Crash Course Exercises - Solutions.ipynb create mode 100644 01_PythonCrashCourse/Python Crash Course Exercises .ipynb create mode 100644 01_PythonCrashCourse/Python Crash Course.ipynb diff --git a/01_PythonCrashCourse/Python Crash Course Exercises - Solutions.ipynb b/01_PythonCrashCourse/Python Crash Course Exercises - Solutions.ipynb new file mode 100644 index 0000000..15b1c82 --- /dev/null +++ b/01_PythonCrashCourse/Python Crash Course Exercises - Solutions.ipynb @@ -0,0 +1,522 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python Crash Course Exercises - Solutions\n", + "\n", + "This is an optional exercise to test your understanding of Python Basics. If you find this extremely challenging, then you probably are not ready for the rest of this course yet and don't have enough programming experience to continue. I would suggest you take another course more geared towards complete beginners, such as [Complete Python Bootcamp]()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercises\n", + "\n", + "Answer the questions or complete the tasks outlined in bold below, use the specific method described if applicable." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** What is 7 to the power of 4?**" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2401" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 **4" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Split this string:**\n", + "\n", + " s = \"Hi there Sam!\"\n", + " \n", + "**into a list. **" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "s = 'Hi there Sam!'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['Hi', 'there', 'dad!']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.split()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given the variables:**\n", + "\n", + " planet = \"Earth\"\n", + " diameter = 12742\n", + "\n", + "** Use .format() to print the following string: **\n", + "\n", + " The diameter of Earth is 12742 kilometers." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "planet = \"Earth\"\n", + "diameter = 12742" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The diameter of Earth is 12742 kilometers.\n" + ] + } + ], + "source": [ + "print(\"The diameter of {} is {} kilometers.\".format(planet,diameter))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given this nested list, use indexing to grab the word \"hello\" **" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst[3][1][2][0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given this nest dictionary grab the word \"hello\". Be prepared, this will be annoying/tricky **" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d['k1'][3]['tricky'][3]['target'][3]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** What is the main difference between a tuple and a list? **" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Tuple is immutable" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a function that grabs the email website domain from a string in the form: **\n", + "\n", + " user@domain.com\n", + " \n", + "**So for example, passing \"user@domain.com\" would return: domain.com**" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def domainGet(email):\n", + " return email.split('@')[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'domain.com'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "domainGet('user@domain.com')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. **" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def findDog(st):\n", + " return 'dog' in st.lower().split()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "findDog('Is there a dog here?')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a function that counts the number of times the word \"dog\" occurs in a string. Again ignore edge cases. **" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def countDog(st):\n", + " count = 0\n", + " for word in st.lower().split():\n", + " if word == 'dog':\n", + " count += 1\n", + " return count" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "countDog('This dog runs faster than the other dog dude!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:**\n", + "\n", + " seq = ['soup','dog','salad','cat','great']\n", + "\n", + "**should be filtered down to:**\n", + "\n", + " ['soup','salad']" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "seq = ['soup','dog','salad','cat','great']" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['soup', 'salad']" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(filter(lambda word: word[0]=='s',seq))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Final Problem\n", + "**You are driving a little too fast, and a police officer stops you. Write a function\n", + " to return one of 3 possible results: \"No ticket\", \"Small ticket\", or \"Big Ticket\". \n", + " If your speed is 60 or less, the result is \"No Ticket\". If speed is between 61 \n", + " and 80 inclusive, the result is \"Small Ticket\". If speed is 81 or more, the result is \"Big Ticket\". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all \n", + " cases. **" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def caught_speeding(speed, is_birthday):\n", + " \n", + " if is_birthday:\n", + " speeding = speed - 5\n", + " else:\n", + " speeding = speed\n", + " \n", + " if speeding > 80:\n", + " return 'Big Ticket'\n", + " elif speeding > 60:\n", + " return 'Small Ticket'\n", + " else:\n", + " return 'No Ticket'" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'Small Ticket'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "caught_speeding(81,True)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'Big Ticket'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "caught_speeding(81,False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Great job!" + ] + } + ], + "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.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/01_PythonCrashCourse/Python Crash Course Exercises .ipynb b/01_PythonCrashCourse/Python Crash Course Exercises .ipynb new file mode 100644 index 0000000..ac12744 --- /dev/null +++ b/01_PythonCrashCourse/Python Crash Course Exercises .ipynb @@ -0,0 +1,484 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python Crash Course Exercises \n", + "\n", + "This is an optional exercise to test your understanding of Python Basics. If you find this extremely challenging, then you probably are not ready for the rest of this course yet and don't have enough programming experience to continue. I would suggest you take another course more geared towards complete beginners, such as [Complete Python Bootcamp](https://www.udemy.com/complete-python-bootcamp)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercises\n", + "\n", + "Answer the questions or complete the tasks outlined in bold below, use the specific method described if applicable." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** What is 7 to the power of 4?**" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2401" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Split this string:**\n", + "\n", + " s = \"Hi there Sam!\"\n", + " \n", + "**into a list. **" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['Hi', 'there', 'dad!']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given the variables:**\n", + "\n", + " planet = \"Earth\"\n", + " diameter = 12742\n", + "\n", + "** Use .format() to print the following string: **\n", + "\n", + " The diameter of Earth is 12742 kilometers." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "planet = \"Earth\"\n", + "diameter = 12742" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The diameter of Earth is 12742 kilometers.\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given this nested list, use indexing to grab the word \"hello\" **" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "lst = [1,2,[3,4],[5,[100,200,['hello']],23,11],1,7]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Given this nested dictionary grab the word \"hello\". Be prepared, this will be annoying/tricky **" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "d = {'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** What is the main difference between a tuple and a list? **" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Tuple is immutable" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a function that grabs the email website domain from a string in the form: **\n", + "\n", + " user@domain.com\n", + " \n", + "**So for example, passing \"user@domain.com\" would return: domain.com**" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'domain.com'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "domainGet('user@domain.com')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a basic function that returns True if the word 'dog' is contained in the input string. Don't worry about edge cases like a punctuation being attached to the word dog, but do account for capitalization. **" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "findDog('Is there a dog here?')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Create a function that counts the number of times the word \"dog\" occurs in a string. Again ignore edge cases. **" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "countDog('This dog runs faster than the other dog dude!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "** Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:**\n", + "\n", + " seq = ['soup','dog','salad','cat','great']\n", + "\n", + "**should be filtered down to:**\n", + "\n", + " ['soup','salad']" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "seq = ['soup','dog','salad','cat','great']" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['soup', 'salad']" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Final Problem\n", + "**You are driving a little too fast, and a police officer stops you. Write a function\n", + " to return one of 3 possible results: \"No ticket\", \"Small ticket\", or \"Big Ticket\". \n", + " If your speed is 60 or less, the result is \"No Ticket\". If speed is between 61 \n", + " and 80 inclusive, the result is \"Small Ticket\". If speed is 81 or more, the result is \"Big Ticket\". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all \n", + " cases. **" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def caught_speeding(speed, is_birthday):\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'Small Ticket'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "caught_speeding(81,True)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'Big Ticket'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "caught_speeding(81,False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Great job!" + ] + } + ], + "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.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/01_PythonCrashCourse/Python Crash Course.ipynb b/01_PythonCrashCourse/Python Crash Course.ipynb new file mode 100644 index 0000000..d4a1474 --- /dev/null +++ b/01_PythonCrashCourse/Python Crash Course.ipynb @@ -0,0 +1,2220 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python Crash Course\n", + "\n", + "Please note, this is not meant to be a comprehensive overview of Python or programming in general, if you have no programming experience, you should probably take my other course: [Complete Python Bootcamp](https://www.udemy.com/complete-python-bootcamp/?couponCode=PY20) instead.\n", + "\n", + "**This notebook is just a code reference for the videos, no written explanations here**\n", + "\n", + "This notebook will just go through the basic topics in order:\n", + "\n", + "* Data types\n", + " * Numbers\n", + " * Strings\n", + " * Printing\n", + " * Lists\n", + " * Dictionaries\n", + " * Booleans\n", + " * Tuples \n", + " * Sets\n", + "* Comparison Operators\n", + "* if,elif, else Statements\n", + "* for Loops\n", + "* while Loops\n", + "* range()\n", + "* list comprehension\n", + "* functions\n", + "* lambda expressions\n", + "* map and filter\n", + "* methods\n", + "____" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Data types\n", + "\n", + "### Numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 / 2" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 ** 4" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 % 2" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 % 2" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2 + 3) * (5 + 5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Variable Assignment" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Can not start with number or special characters\n", + "name_of_var = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "x = 2\n", + "y = 3" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "z = x + y" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "z" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Strings" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'single quotes'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'single quotes'" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'double quotes'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"double quotes\"" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\" wrap lot's of other quotes\"" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\" wrap lot's of other quotes\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Printing" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "x = 'hello'" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello\n" + ] + } + ], + "source": [ + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "num = 12\n", + "name = 'Sam'" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My number is: 12, and my name is: Sam\n" + ] + } + ], + "source": [ + "print('My number is: {one}, and my name is: {two}'.format(one=num,two=name))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My number is: 12, and my name is: Sam\n" + ] + } + ], + "source": [ + "print('My number is: {}, and my name is: {}'.format(num,name))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Lists" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[1,2,3]" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['hi', 1, [1, 2]]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "['hi',1,[1,2]]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "my_list = ['a','b','c']" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "my_list.append('d')" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c', 'd']" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'b'" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['b', 'c', 'd']" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list[1:]" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['a']" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list[:1]" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "my_list[0] = 'NEW'" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['NEW', 'b', 'c', 'd']" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_list" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "nest = [1,2,3,[4,5,['target']]]" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[4, 5, ['target']]" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nest[3]" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['target']" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nest[3][2]" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'target'" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nest[3][2][0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Dictionaries" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "d = {'key1':'item1','key2':'item2'}" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'key1': 'item1', 'key2': 'item2'}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'item1'" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d['key1']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Booleans" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "True" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Tuples " + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "t = (1,2,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "t[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'tuple' object does not support item assignment", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'NEW'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" + ] + } + ], + "source": [ + "t[0] = 'NEW'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Sets" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3}" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{1,2,3}" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{1, 2, 3}" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{1,2,3,1,2,1,2,3,3,3,3,2,2,2,1,1,2}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Comparison Operators" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 > 2" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 < 2" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 >= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 <= 4" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 == 1" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hi' == 'bye'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Logic Operators" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(1 > 2) and (2 < 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(1 > 2) or (2 < 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(1 == 2) or (2 == 3) or (4 == 4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## if,elif, else Statements" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yep!\n" + ] + } + ], + "source": [ + "if 1 < 2:\n", + " print('Yep!')" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "yep!\n" + ] + } + ], + "source": [ + "if 1 < 2:\n", + " print('yep!')" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first\n" + ] + } + ], + "source": [ + "if 1 < 2:\n", + " print('first')\n", + "else:\n", + " print('last')" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "last\n" + ] + } + ], + "source": [ + "if 1 > 2:\n", + " print('first')\n", + "else:\n", + " print('last')" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "middle\n" + ] + } + ], + "source": [ + "if 1 == 2:\n", + " print('first')\n", + "elif 3 == 3:\n", + " print('middle')\n", + "else:\n", + " print('Last')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## for Loops" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "seq = [1,2,3,4,5]" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "for item in seq:\n", + " print(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yep\n", + "Yep\n", + "Yep\n", + "Yep\n", + "Yep\n" + ] + } + ], + "source": [ + "for item in seq:\n", + " print('Yep')" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "6\n", + "8\n", + "10\n" + ] + } + ], + "source": [ + "for jelly in seq:\n", + " print(jelly+jelly)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## while Loops" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i is: 1\n", + "i is: 2\n", + "i is: 3\n", + "i is: 4\n" + ] + } + ], + "source": [ + "i = 1\n", + "while i < 5:\n", + " print('i is: {}'.format(i))\n", + " i = i+1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## range()" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "range(0, 5)" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "range(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "for i in range(5):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 4]" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(range(5))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## list comprehension" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "x = [1,2,3,4]" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16]\n" + ] + } + ], + "source": [ + "out = []\n", + "for item in x:\n", + " out.append(item**2)\n", + "print(out)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16]" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[item**2 for item in x]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## functions" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def my_func(param1='default'):\n", + " \"\"\"\n", + " Docstring goes here.\n", + " \"\"\"\n", + " print(param1)" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_func" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "default\n" + ] + } + ], + "source": [ + "my_func()" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "new param\n" + ] + } + ], + "source": [ + "my_func('new param')" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "new param\n" + ] + } + ], + "source": [ + "my_func(param1='new param')" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def square(x):\n", + " return x**2" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "out = square(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "print(out)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## lambda expressions" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def times2(var):\n", + " return var*2" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "times2(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + ">" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lambda var: var*2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## map and filter" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "seq = [1,2,3,4,5]" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "map(times2,seq)" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10]" + ] + }, + "execution_count": 85, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(map(times2,seq))" + ] + }, + { + "cell_type": "code", + "execution_count": 86, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 6, 8, 10]" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(map(lambda var: var*2,seq))" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "filter(lambda item: item%2 == 0,seq)" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4]" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(filter(lambda item: item%2 == 0,seq))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## methods" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "st = 'hello my name is Sam'" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello my name is sam'" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "st.lower()" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'HELLO MY NAME IS SAM'" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "st.upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['hello', 'my', 'name', 'is', 'Sam']" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "st.split()" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "tweet = 'Go Sports! #Sports'" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['Go Sports! ', 'Sports']" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tweet.split('#')" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'Sports'" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tweet.split('#')[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'key1': 'item1', 'key2': 'item2'}" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['key2', 'key1'])" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_items([('key2', 'item2'), ('key1', 'item1')])" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "d.items()" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "lst = [1,2,3]" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst.pop()" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'x' in [1,2,3]" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'x' in ['x','y','z']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Great Job!" + ] + } + ], + "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.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}