<jupyter_start><jupyter_text>Intro of this notebook:In this notebook we are going to get familiar with Python. We will cover the basic portion of Python which can be very useful for Machine Learning. **A simple effort from me to make a Python bootcamp 3 Days for beginners who are enthusiastic about Machine Learning.**![Imgur](https://i.imgur.com/XcoYcRP.jpg)  Now Lets Start!✌  &128204; Code , Style, and Links<jupyter_code>%%html
<style>
@import url('https://fonts.googleapis.com/css?family=Ewert|Roboto&effect=3d|ice|');
body {background-color: gainsboro;} 
a {color: #000000; font-family: 'Roboto';} 
h1 {color: #000000; font-family: 'Orbitron'; text-shadow: 4px 4px 4px #aaa;} 
h2, h3 {color: slategray; font-family: 'Orbitron'; text-shadow: 4px 4px 4px #aaa;}
h4 {color: #818286; font-family: 'Roboto';}
span {font-family:'Roboto'; color:black; text-shadow: 5px 5px 5px #aaa;}  
div.output_area pre{font-family:'Roboto'; font-size:110%; color:lightblue;}      
</style><jupyter_output><empty_output><jupyter_text>&128209; Table of Content : Python Basic*  Introduction of python* Features of Python programming language*  Implementation of python   *  Variables and Maths Operations  *   Casting  *   String  *   List  *   Tuples  *   Sets  *   Dictionaries  *   User Input  &128214; 1. Python Basic ![Imgur](https://i.imgur.com/POruZ9g.jpg?1)  1.1 Introduction of Python : Python is developed by <NAME>. <NAME> Rossum started implementing Python in 1989. Python is a general-purpose,	object-oriented	and	open source	computer programming language, it is a high-level, human-readable and a	corresponding set of software tools and libraries.> Interesting fact: Python is named after the comedy television show Monty Python’s Flying Circus. It is not named after the Python snake.  1.2 Features of Python programming language:1. **Readable:** Python is a very readable language.2. **Easy to Learn:** Learning python is easy as this is a expressive and high level programming language, which means it is easy to understand the language and thus easy to learn.3. **Cross platform: **Python is available and can run on various operating systems such as Mac, Windows, Linux, Unix etc. This makes it a cross platform and portable language.4. **Open Source:** Python is a open source programming language.5. **Large standard library:** Python comes with a large standard library that has some handy codes and functions which we can use while writing code in Python.6. ** Free:** Python is free to download and use. This means you can download it for free and use it in your application. See: Open Source Python License7. **Supports exception handling:** If you are new, you may wonder what is an exception? An exception is an event that can occur during program exception and can disrupt the normal flow of program. Python supports exception handling which means we can write less error prone code and can test various scenarios that can cause an exception later on.8. **Advanced features:** Supports generators and list comprehensions. We will cover these features later.9. **Automatic memory management:** Python supports automatic memory management which means the memory is cleared and freed automatically. You do not have to bother clearing the memory.  &128187; 1.3 Implementation of Python :  1.3.1 How to Install Python:You can install Python on any operating system such as Windows, Mac OS X, Linux/Unix and others.To install the Python on your operating system, go to this [link](https://www.python.org/downloads/). You will see a screen like this.![Imgur](https://i.imgur.com/AOt6Jpu.png)This is the **official Python website** and it will detect the operating system and based on that it would recommend you to download Python. Here I am using Windows  so it gave me the download options for Python 2 and Python 3 for Windows. I would recommend you to download the ** latest version of Python 3 **(Python 3.7.2 in the screenshot).Installation steps are pretty simple. You just have to accept the agreement and finish the installation.  1.3.1 Variables & Math Operations **Variables :**An equal (=) sign is used to store a value in a variable. Until then, we did not use any variables in the chapters. So whenever we press any key number, text or statement in the Python console and press Enter, its output shows the next line. But if we store a value in a variable (with the equal sign) and press enter, then the next line will not output. Rather, the right side of the equal sign will be stored in the variant on the left side of the equal sign, which we can use to name it in the next statement.Variable is like a small box made in computer memory, in which anything can be stored. When we declare a variable, the computer determines certain memory for that variable. Each variable's memory address is unique. The value of the program can be stored in the memory location filled in the name of the variable name. Once again, using that name, the value of that location can be accessed and used to be useful.<jupyter_code>X = 'Python is good for ML'
print(X)
ML = 5 
print(ML)
DL= ML + 8 
print(DL)<jupyter_output><empty_output><jupyter_text>In the above example, initially, 'Python is good for ML' ( a string ) is stored in a variable X. In the next line, the print () function has been sent to the X as the argument. And we already know that if you send something as print function argument, then it is printed. So, ML number 5 is printed on screen. Similar works were done in print (ML + 8) line Here the print (5+ 8) is basically executed, because the value of ML is 5. And with the addition of 8 the number 13 has been sent as the print function argument which is printed on the screen. **Math  Operations: ** Mathematical calculations can easily be done in Python Console. **Operation** | **Operator** | ------------ | ------------ | Addition |        +Subtraction |  -Multiplication | *Division | / Remainder| %Integer Division | // Exponentiation | ** Under the following mathematical command, the results are easily found -<jupyter_code>5+8
5+8-6<jupyter_output><empty_output><jupyter_text>Just like the addition of subtraction, the work of multiplication can be easily done here. Using a bracket can be defined that any part of the operation will be done before the operation.<jupyter_code>5*(8+6)
8/6<jupyter_output><empty_output><jupyter_text>When using a single / share, the result comes in the float type decimal. The addition of addition, subtraction, multiplication, there is support for expansion in Python, which we call a number to get on a number. This operation is done with two ** signs. For example -<jupyter_code>5**8<jupyter_output><empty_output><jupyter_text>The modulo operator is used only for determining the floor division and for determining the quotient. The floor division is done using two forward slashes **```//```** and the modulo operator is done with **```%```** symbol. See the example below -<jupyter_code>8//5
8%5<jupyter_output><empty_output><jupyter_text>1.3.2 Casting Casting Conversion means to convert variables from one type to another. It is a type of casting and is called. Python has some built-in functions for type casting. We can use them easily if we want to. Up until now we have learned about integers, floats, and strings data types. To convert this type, the functions are being respectively - **```int (), float, str ()```.** **Integer casting:** The int () function is used to convert from strings or floats into angles.<jupyter_code>int('458')
int(58.4)<jupyter_output><empty_output><jupyter_text>**String casting:** Use the str () function without any restriction to convert it to any variable strings.<jupyter_code>str(58)
str(13)<jupyter_output><empty_output><jupyter_text>When we write multiple variables inside the print () function, string converts should be used.<jupyter_code>print("Float = " + str(8.4) + " Integer = " + str(45))<jupyter_output><empty_output><jupyter_text>**Float casting:** The float () function is used to convert from strings or integers to float.<jupyter_code>float(58)
float("58.4")<jupyter_output><empty_output><jupyter_text>1.3.3 StringStrings are used in Python to record text information, such as name. Strings in Python are actually a sequence, which basically means Python keeps track of every element in the string as a sequence. For example, Python understands the string "hello' to be a sequence of letters in a specific order. This means we will be able to use indexing to grab particular letters (like the first letter, or the last letter). In this lecture we'll learn about the following:1. Creating Strings2. Printing Strings3. Differences in Printing in Python 2 vs 34. String Indexing and Slicing5. String Properties6. String Methods7. Print Formatting   1.Creating String To create a string in Python you need to use either single quotes or double quotes. For example:<jupyter_code># Single word
'Machine'<jupyter_output><empty_output><jupyter_text>Entire phrase :<jupyter_code>'Python Bootcamp'<jupyter_output><empty_output><jupyter_text>We can also use double quote:<jupyter_code>"Machine built  string with double quotes"<jupyter_output><empty_output><jupyter_text>Be careful with quotes! show in the below that:<jupyter_code>'I'm using single quotes, but will create an error'<jupyter_output><empty_output><jupyter_text>The reason for the error above is because the single quote in I'm stopped the string. You can use combinations of double and single quotes to get the complete statement.<jupyter_code>"Now I'm ready to use the single quotes inside a string By Machine!"<jupyter_output><empty_output><jupyter_text>Now let's learn about printing strings!  2.Printing a StringUsing Jupyter notebook with just a string in a cell will automatically output strings, but the correct way to display strings in your output is by using a print function. We can simply declare a string<jupyter_code>'Hey Machine Learning'<jupyter_output><empty_output><jupyter_text>note that we can't output multiple strings this way<jupyter_code>'Machine Learning'
'Hey Machine Learning'<jupyter_output><empty_output><jupyter_text>3. Differences in Printing in Python 2 vs 3 We can use a print statement to print a string. **Input Screen:**``print 'Machine Learning'print 'Hey Machine Learning'print 'Use \n to print a new line'print '\n'print 'See what I mean?`` **Output Screen:**Machine LearningHey Machine LearningUse  to print a new lineSee what I mean? Something to note. In Python 3, print is a function, not a statement. So you would print statements like this: print('Hello World')If you want to use this functionality in Python2, you can import form the future module. A word of caution, after importing this you won't be able to choose the print statement method anymore. So pick whichever one you prefer depending on your Python installation and continue on with it.<jupyter_code># To use print function from Python 3 in Python 2
from __future__ import print_function

print('Hey Machine Learning')<jupyter_output><empty_output><jupyter_text>String BasicsWe can also use a function called len() to check the length of a string!<jupyter_code>len('Hey Machine')<jupyter_output><empty_output><jupyter_text>4. String Indexing and SlicingWe know strings are a sequence, which means Python can use indexes to call parts of the sequence. Let's learn how this works.In Python, we use brackets [] after an object to call its index. We should also note that indexing starts at 0 for Python. Let's create a new object called s and the walk through a few examples of indexing.<jupyter_code># Assign s as a string
M = '<NAME>'
#Check
M
# Print the object
print(M)<jupyter_output><empty_output><jupyter_text>Let's start indexing!<jupyter_code>M[0]
M[2]
M[-2]<jupyter_output><empty_output><jupyter_text>We can use a : to perform slicing which grabs everything up to a designated point. For example:<jupyter_code># Grab everything past the first term all the way to the length of M which is len(M)
M[1:]
# Note that there is no change to the original M
M
# Grab everything UP TO the 3rd index
M[:3]<jupyter_output><empty_output><jupyter_text>Note the above slicing. Here we're telling Python to grab everything from 0 up to 3. It doesn't include the 3rd index. You'll notice this a lot in Python, where statements and are usually in the context of "up to, but not including".<jupyter_code>#Everything
M[:]<jupyter_output><empty_output><jupyter_text>We can also use negative indexing to go backwards.<jupyter_code># Last letter (one index behind 0 so it loops back around)
M[-1]
# Grab everything but the last letter
M[:-1]<jupyter_output><empty_output><jupyter_text>We can also use index and slice notation to grab elements of a sequence by a specified step size (the default is 1). For instance we can use two colons in a row and then a number specifying the frequency to grab elements. For example:<jupyter_code># Grab everything, but go in steps size of 1
M[::1]
# Grab everything, but go in step sizes of 2
M[::2]
# We can use this to print a string backwards
M[::-1]<jupyter_output><empty_output><jupyter_text>5.String PropertiesIts important to note that strings have an important property known as immutability. This means that once a string is created, the elements within it can not be changed or replaced. For example:<jupyter_code>M
# Let's try to change the first letter to 'x'
M[0] = 'X'<jupyter_output><empty_output><jupyter_text>Notice how the error tells us directly what we can't do, change the item assignment!Something we can do is concatenate strings!<jupyter_code>M
# Concatenate strings!
M+' Learning!'
# We can reassign s completely though!
M=M+' Learning!'
print(M)
M<jupyter_output><empty_output><jupyter_text>We can use the multiplication symbol to create repetition!<jupyter_code>letter='M'
letter*20<jupyter_output><empty_output><jupyter_text>6.Basic Built-in String methodsObjects in Python usually have built-in methods. These methods are functions inside the object (we will learn about these in much more depth later) that can perform actions or commands on the object itself.We call methods with a period and then the method name. Methods are in the form:object.method(parameters)Where parameters are extra arguments we can pass into the method. Don't worry if the details don't make 100% sense right now. Later on we will be creating our own objects and functions!Here are some examples of built-in methods in strings:<jupyter_code>M
#Upper case a string
M.upper()
#Lower case a string
M.lower()
# Split a string by blank space (this is the default)
M.split()
# Split by a specific element (doesn't include the element that was split on)
M.split('Learning')<jupyter_output><empty_output><jupyter_text>There are many more methods than the ones covered here. Visit the advanced String section to find out more!  7.Print FormattingWe can use the .format() method to add formatted objects to printed string statements.The easiest way to show this is through an example:<jupyter_code>'Insert another Bootcamp with curly brackets: {}'.format('The Machine Learning BootCamp!')<jupyter_output><empty_output><jupyter_text>We will revisit this string formatting topic in later sections when we are building our projects!  1.3.4 List Lists are just like the arrays, declared in other languages. Lists need not be homogeneous always which makes it a most powerful tool in Python. A single list may contain DataTypes like Integers, Strings, as well as Objects. Lists are also very useful for implementing stacks and queues. Lists are mutable, and hence, they can be altered even after their creation.![Imgur](https://i.imgur.com/Ok9i6nm.png)In Python, list is a type of container in Data Structures, which is used to store multiple data at the same time. Unlike Sets, the list in Python are ordered and have a definite count. The elements in a list are indexed according to a definite sequence and the indexing of a list is done with 0 being the first index. Each element in the list has its definite place in the list, which allows duplicating of elements in the list, with each element having its own distinct place and credibility.Note- Lists are a useful tool for preserving a sequence of data and further iterating over it.<jupyter_code>names = ["Pi", "Bike", "!"]
print(names[0])
print(names[1])
print(names[2])<jupyter_output><empty_output><jupyter_text>1.3.4.1 Empty An empty list can be made as below -<jupyter_code>empty_list = []
print(empty_list)<jupyter_output><empty_output><jupyter_text>1.3.4.2  Mixed ListA mixed list can be made as below-<jupyter_code>mix_list = ['Pi', 3, 3.14, True]
print (mix_list)<jupyter_output><empty_output><jupyter_text>1.3.4.3  2D List or MatrixA 2D list of matrix can be made as below-<jupyter_code>matrix = [ [1, 2, 3, 4, 5],
           [4, 5, 6, 7, 8],
           [1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0]
          ]
print(matrix)<jupyter_output><empty_output><jupyter_text>1.3.4.4 Nested listA nested list can be made as below-<jupyter_code>matrix = [ [2, 2, 3, 4, 4],
           [4, 5, 6, 7, 9],
           [1, 1, 1, 1, 1],
           [0, 0, 0, 0, 0]
          ]
                    
for x in matrix:
    for y in x:
        print (y, end=' ')
    print()<jupyter_output><empty_output><jupyter_text>1.3.4.5 List slicingA list slicing can be made as below--<jupyter_code>numbers_list = [4, 5, 7, 8, 9]
print ( numbers_list[0 : 2] )
print ( numbers_list[2 : -2])<jupyter_output><empty_output><jupyter_text>1.3.4.6 List iteration by for loopA list iteration by for loop can be made as below--<jupyter_code>bikes = ['pibike', 'hellobike', 'mobike']
for bike in bikes:
    print (bike)
    if (bike == 'hellobike'):
        print ("I love hellobike")<jupyter_output><empty_output><jupyter_text>1.3.4.7  Sum of list numbersA  sum of list numbers can be made as below--<jupyter_code>list_of_number = [1, 7, 3, 4, 5]
sum = 0
for num in list_of_number:
    sum += num
print ("Sum is: {sum}".format(sum=sum))<jupyter_output><empty_output><jupyter_text>A sum of list numbers with string can be made as below---<jupyter_code>list_of_number = [1, 8, 'bike', 4, 5.5, 5]
sum = 0
for num in list_of_number:
    if type(num) == int:
        sum += num
print ("Sum is: {sum}".format(sum=sum))<jupyter_output><empty_output><jupyter_text>1.3.4.8  List modificationA list modification can be made as below--<jupyter_code>mix_list = ['mobike', 28, 5.4, True]
print(mix_list)
mix_list[0] = 'hellobike'
print(mix_list)<jupyter_output><empty_output><jupyter_text>1.3.4.9  Adding item in listA adding item in list can be made as below--<jupyter_code>mix_list.append('pibike')
print(mix_list)
mix_list.insert(2, 'ofobike')
print(mix_list)
mix_list += ['ohbike'] # shortcut version for adding item
print(mix_list)<jupyter_output><empty_output><jupyter_text>1.3.4.10  Deleting item in listA  deleting item in list can be made as below--<jupyter_code>bikes = ['pibike', 'hellobike', 'mobike']
del bikes[1]
print( bikes )<jupyter_output><empty_output><jupyter_text>1.3.4.11 Get and remove item using pop()A get and remove item using pop() can be made as below--<jupyter_code>bikes = ['pibike', 'hellobike', 'mobike']
last_bike=bikes.pop()# last item
print(bikes, "\n", last_bike)
bikes = ['pibike', 'hellobike', 'mobike']
third_bike = bikes.pop(1) # third item
print(bikes, "\n", third_bike)<jupyter_output><empty_output><jupyter_text>1.3.4.12 Splitting String into List itemsA splitting string into list items can be made as below--<jupyter_code>import re
cars = "toyota, hellobike, bmw, audi"
# cars = ['toyota', 'honda', 'bmw', 'audi']
car_list = re.split(',', cars)
print(car_list)<jupyter_output><empty_output><jupyter_text>1.3.4.13 List's string item concatnationA list's string item concatnation can be made as below--<jupyter_code>quote = ['Just', 'get','up','and','do','it,','follow','your','dreams!']
print(quote)
quote_str = ' '.join(quote)
print(quote_str)<jupyter_output><empty_output><jupyter_text>1.3.4.14 List length A list length can be made as below--<jupyter_code>numbers = [1, 'bike', 3, 4]
print (len(numbers))<jupyter_output><empty_output><jupyter_text>1.3.4.15 Reversing listA reversing list can be made as below--<jupyter_code>reverse_list = ['Mobike', 'Hellobike', 3, 4]
reverse_list.reverse()
print(reverse_list)<jupyter_output><empty_output><jupyter_text>1.3.4.16 List Comprehensions In addition to sequence operations and list methods, Python includes a more advanced operation called a list comprehension.![Imgur](https://i.imgur.com/O14brf9.png)List comprehensions allow us to build out lists using a different notation. You can think of it as essentially a one line for loop built inside of brackets.<jupyter_code>lst = [ x**2 for x in [x**2 for x in range(11)]]
lst<jupyter_output><empty_output><jupyter_text>1.3.5 Tuples A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.Creating a tuple is as simple as putting different comma-separated values. Optionally you can put these comma-separated values between parentheses also.![Imgur](https://i.imgur.com/dWSQIZo.png)In this section, we will get a brief overview of the following:1.Constructing Tuples2.Basic Tuple Methods3.Immutability4.When to Use Tuples.You'll have an intuition of how to use tuples based on what you've learned about lists. We can treat them very similarly with the major distinction being that tuples are immutable.  1. Constructing Tuples The construction of a tuples use () with elements separated by commas. For example: Can create a tuple with mixed types<jupyter_code>t = (4,5,7,9)<jupyter_output><empty_output><jupyter_text>Check len just like a list<jupyter_code>len(t)<jupyter_output><empty_output><jupyter_text>Can also mix object types<jupyter_code>t = ('five',2)
t<jupyter_output><empty_output><jupyter_text>Use indexing just like we did in lists<jupyter_code>t[0]<jupyter_output><empty_output><jupyter_text>Slicing just like a list<jupyter_code>t[-1]<jupyter_output><empty_output><jupyter_text>2.Basic Tuple MethodsTuples have built-in methods, but not as many as lists do. Lets look at two of them:<jupyter_code># Use .index to enter a value and return the index
t.index('five')
# Use .count to count the number of times a value appears
t.count('four')<jupyter_output><empty_output><jupyter_text>3.ImmutabilityIt can't be stressed enough that tuples are immutable. To drive that point home:<jupyter_code>t[0]= 'change'<jupyter_output><empty_output><jupyter_text>Because of this immutability, tuples can't grow. Once a tuple is made we can not add to it.<jupyter_code>t.append('nope')<jupyter_output><empty_output><jupyter_text>4. When to use TuplesYou may be wondering, "Why bother using tuples when they have fewer available methods?" To be honest, tuples are not used as often as lists in programming, but are used when immutability is necessary. If in your program you are passing around an object and need to make sure it does not get changed, then tuple become your solution. It provides a convenient source of data integrity.You should now be able to create and use tuples in your programming as well as have an understanding of their immutability.  1.3.6 SetsA set is an unordered collection of items. Every element is unique (no duplicates) and must be immutable (which cannot be changed).However, the set itself is mutable. We can add or remove items from it.Sets can be used to perform mathematical set operations like union, intersection, symmetric difference etc.![Imgur](https://i.imgur.com/MzFKDv6.png)Sets are an unordered collection of unique elements. We can construct them by using the set() function. Let's go ahead and make a set to see how it works:<jupyter_code>x = set()
# We add to sets with the add() method
x.add(1)
#Show
x<jupyter_output><empty_output><jupyter_text>Note the curly brackets. This does not indicate a dictionary! Although you can draw analogies as a set being a dictionary with only keys.We know that a set has only unique entries. So what happens when we try to add something that is already in a set?<jupyter_code># Add a different element
x.add(3)
#Show
x
# Try to add the same element
x.add(1)
#Show
x<jupyter_output><empty_output><jupyter_text>Notice how it won't place another 1 there. That's because a set is only concerned with unique elements! We can cast a list with multiple repeat elements to a set to get the unique elements. For example:<jupyter_code># Create a list with repeats
l = [1,1,2,2,3,4,5,6,1,1]
# Cast as set to get unique values
set(l)<jupyter_output><empty_output><jupyter_text>1.3.6.1 Set UnionUnion of A and B is a set of all elements from both sets.Union is performed using ``|`` operator. Same can be accomplished using the method ``union()``.<jupyter_code># initialize A and B
A = {4, 5, 6, 4, 5}
B = {4, 5, 6, 7, 8}
# use | operator
print(A | B)<jupyter_output><empty_output><jupyter_text>1.3.6.2 Set IntersectionIntersection of A and B is a set of elements that are common in both sets.Intersection is performed using ``&`` operator. Same can be accomplished using the method ``intersection()``.<jupyter_code># initialize A and B
A = {8, 9, 3, 4, 5}
B = {4, 5, 6, 7, 8}
# use & operator
print(A & B)<jupyter_output><empty_output><jupyter_text>1.3.6.3 Set DifferenceDifference of A and B (A - B) is a set of elements that are only in A but not in B. Similarly, B - A is a set of element in B but not in A.Difference is performed using ``-``operator. Same can be accomplished using the method ``difference()``.<jupyter_code># initialize A and B
A = {13, 8, 3, 4, 5}
B = {4, 5, 6, 7, 8}
# use - operator on A
print(A - B)<jupyter_output><empty_output><jupyter_text>1.3.6.4 Set Symmetric DifferenceSymmetric Difference of A and B is a set of elements in both A and B except those that are common in both.Symmetric difference is performed using ``^`` operator. Same can be accomplished using the method ``symmetric_difference()``.<jupyter_code># initialize A and B
A = {13, 18, 3, 4, 5}
B = {4, 5, 6, 7, 8}
# use ^ operator
print(A ^ B)<jupyter_output><empty_output><jupyter_text>1.3.7 DictionariesPython dictionary is an unordered collection of items. While other compound data types have only value as an element, a dictionary has a key: value pair.Dictionaries are optimized to retrieve values when the key is known.![Imgur](https://i.imgur.com/XDoXiGy.png)We've been learning about sequences in Python but now we're going to switch gears and learn about mappings in Python. If you're familiar with other languages you can think of these Dictionaries as hash tables.This section will serve as a brief introduction to dictionaries and consist of:1. Constructing a Dictionary2. Accessing objects from a dictionary3. Nesting Dictionaries4. Basic Dictionary MethodsA Python dictionary consists of a key and then an associated value. That value can be almost any Python object.  1 Constructing a DictionaryLet's see how we can construct dictionaries to get a better understanding of how they work!<jupyter_code># Make a dictionary with {} and : to signify a key and a value
my_dict = {'key1':'value1','key2':'value2'}
# Call values by their key
my_dict['key2']<jupyter_output><empty_output><jupyter_text>Its important to note that dictionaries are very flexible in the data types they can hold. For example:<jupyter_code>my_dict = {'key1':123,'key2':[12,23,33],'key3':['item0','item1','item2']}
#Lets call items from the dictionary
my_dict['key3']
# Can call an index on that value
my_dict['key3'][0]
#Can then even call methods on that value
my_dict['key3'][0].upper()<jupyter_output><empty_output><jupyter_text>A quick note, Python has a built-in method of doing a self subtraction or addition (or multiplication or division). We could have also used += or -= for the above statement. For example:<jupyter_code># Set the object equal to itself minus 123 
my_dict['key1'] -= 123
my_dict['key1']<jupyter_output><empty_output><jupyter_text>2. Accessing objects from a dictionaryWe can also create keys by assignment. For instance if we started off with an empty dictionary, we could continually add to it:<jupyter_code># Create a new dictionary
d = {}
# Create a new key through assignment
d['animal'] = 'Dog'
# Can do this with any object
d['answer'] = 52
#Show
d<jupyter_output><empty_output><jupyter_text>3.Nesting with DictionariesHopefully you're starting to see how powerful Python is with its flexibility of nesting objects and calling methods on them. Let's see a dictionary nested inside a dictionary:<jupyter_code># Dictionary nested inside a dictionary nested in side a dictionary
d = {'key1':{'nestkey':{'subnestkey':'value'}}}<jupyter_output><empty_output><jupyter_text>Wow! That's a quite the inception of dictionaries! Let's see how we can grab that value:<jupyter_code># Keep calling the keys
d['key1']['nestkey']['subnestkey']<jupyter_output><empty_output><jupyter_text>4.Basic Dictionary MethodsThere are a few methods we can call on a dictionary. Let's get a quick introduction to a few of them:<jupyter_code># Create a typical dictionary
d = {'key1':13,'key2':47,'key3':3}
# Method to return a list of all keys 
d.keys()
# Method to grab all values
d.values()
# Method to return tuples of all items  (we'll learn about tuples soon)
d.items()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08802721088435374, 'fraction_numerical': 0.017448979591836736, 'mean_word_length': 5.176680672268907, 'pattern_counts': {'":': 0, '<': 286, '<?xml version=': 0, '>': 287, 'https://': 10, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 20, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '70', 'dir': 'jupyter-structured-clean-dedup', 'id': '203381', 'license': 'MIT', 'n_tokens_mistral': 9054, 'n_tokens_neox': 8592, 'n_words': 3861, 'path': 'python-bootcamp-part-1.ipynb', 'repo_name': 'harunshimanto/Python-Bootcamp-with-ML', 'size': '29418'}