From c521370b3bd0410bb357d4c4ebb76abd7725c858 Mon Sep 17 00:00:00 2001
From: Danielle Anzelone <32557138+danzelo1@users.noreply.github.com>
Date: Sun, 7 Jun 2020 11:45:54 -0400
Subject: [PATCH 1/7] Create Storing_Data_in_Python.md
Uploading my entry blog
---
.../Storing_Data_in_Python.md | 253 ++++++++++++++++++
1 file changed, 253 insertions(+)
create mode 100644 IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
new file mode 100644
index 0000000..db891c7
--- /dev/null
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -0,0 +1,253 @@
+# Storing Data in Python
+
+When we think about Python, we can think of tons of applications for our potential code; we can create a desktop application, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is learning to store pieces of data that will be useful to our program and, more importantly, deciding how we will store this data. Lists, sets, and dictionaries are the most common ways to store data and, in this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.
+
+The first data structure I will talk about is probably the most commonly used in Python - lists. With this method, you can store variables of the same type in a specific order and access and modify them using an index.
+
+## Lists
+
+**Initialization**
+
+*list= [element1, element2, …, elementn]*
+
+When you initialize a list, you must give it a name. If you choose to add elements to the list at this time (optional), they must be separated by commas and wrapped in square brackets, [].
+
+Ex: Take a list of integers called **numbers**. Let’s suppose you want it to contain numbers 0-4. This is how we would initialize the list:
+
+
numbers = [0, 1, 2, 3, 4]
+
+If we wanted **numbers** initialized to be empty, its declaration would look like this:
+
+numbers = []
+
+**Accessing an Element**
+
+*list[index]*
+
+Quite possibly the most important thing to keep in mind when using a Python list is how indices are numbered. When we count in programming, we always start at 0, not 1. So, when we keep track of the index of a list, the first index is always numbered ‘0’. This means that if your list has six elements, the last element is stored at index ‘5’.
+
+With that being said, we can access an element using square brackets, [], and its index.
+
+Ex: If we want to access the fourth element (index 3) and save it to a variable **x**, we would call:
+
+x = numbers[3]
+
+“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that you are assigning a value to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. We are not modifying the variable on the right at all. So, in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
+
+**Modifying an Element**
+
+*list[index] = new element*
+
+Just as we can access an element and assign its value to a variable (like we did above), we can also modify the value of an element given its index.
+
+Ex: If we wanted to change the third value of the list (index 2) to 10, we would call the following:
+
+numbers[2] = 10
+
+The “numbers[2]” accesses the list at index 2 using the brackets, []. By putting an equals sign, “=”, to the right of it, we are indicating that we want to reassign numbers[2]’s value to the value on the right of the “=” – in this instance, it is 10.
+
+**Adding an Element**
+
+*append(new_element)*
+
+*insert(new_element, index)*
+
+Say we want to add the number ‘5’ to our **numbers** list. If we had a specific position in mind, we would need to find that position’s index and call insert() using ‘5’ and the index as parameters.
+
+Ex: If we wanted to place 5 at index 2, we would use the following statement:
+
+ numbers.insert(5, 2)
+
+Now, the contents of numbers is: **[0, 1, 2, 3, 4, 5]**. However, if we wanted to tack ‘5’ onto the end of the list, we would simply use the append() function and pass 5 as a parameter.
+
+numbers.append(5)
+
+Here, the contents of numbers is: **[0, 1, 2, 3, 4, 5]**
+
+The append() function is very user-friendly because it lets you append list onto one another.
+
+letters = [‘a’, ‘b’, ‘c’]
+
+numbers.append(letters)
+
+Now the contents of numbers is: **[0, 1, 2, 3, 4, ‘a’, ‘b’, ‘c]**
+
+Because of how Python is designed, if we insert an element at an index, the list automatically expands and shifts all the elements to the right of the given index one position to the right.
+
+**Removing an Element**
+
+*pop(index)*
+
+*remove(index)*
+
+There are two ways in which we can remove an element - according to its index or according to its value. In the first case, we use the pop() function on the list to remove an element at a given index.
+
+Ex: If we wanted to remove the fifth element (index 4) of our original list, we would call:
+
+numbers.pop(4)
+
+Now the contents of numbers is: **[0, 1, 2, 3]**
+
+However, if we wanted to remove an element without using its index, then we would use remove() and pass the element as the parameter.
+
+To better show this technique, let’s use a list of strings as an example:
+
+Let’s define a list called **fruits** where fruits = **[“apple”, “strawberry”, “orange”, “banana”].**
+
+If we wanted to remove “orange” from the list, we would call
+
+fruits.remove(“orange”)
+
+Which would result in the list: **[“apple”, “strawberry”, “banana”]**
+
+The next method for storing data that we will go over is sets. Sets allow you to store variables of the same type in a group – however, a set is unordered and each element must be unique.
+
+ ## Sets
+
+**Initialization**
+
+*set = {element1, element2, …, elementn}*
+
+Similar to a list, you can initialize a set to be empty, or you can add elements. However, with a set, we use curly brackets, {}, instead of square brackets, [], to initialize its values.
+
+Ex: fruit = {“apple”, “strawberry”, “banana”}
+
+fruit = {}
+
+**Accessing an Element**
+
+Since sets are unordered and do not have indices, you cannot access a specific item in it as you would in a list.
+
+ **Modifying an Element**
+
+Unfortunately, once an item is added to a set, it cannot be modified, only removed. This is because there is no way to access the element to modify it since there are no indices.
+
+**Adding an Element**
+
+*set.add(new_element)*
+
+*set.update(new_element1, new_element2, …, new_elementn)*
+
+Sets have an add() function that takes a variable of the same type as the rest of the set and appends it to the set. Since sets are unordered, there is no need to worry about where you should place it like you would when adding an item to a list.
+
+Ex: fruits.add(“orange”)
+
+Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”}**
+
+You can also append multiple items at once using update() by passing several elements.
+
+Ex:fruits.add([“orange”, “pineapple”, “mango”])
+
+Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”, “pineapple”, “mango”}**
+
+**Removing an Element**
+
+*set.remove(element)*
+
+*set.discard(element)*
+
+There are two functions that you may use to remove an element from a set. Both require that you pass the element you wish to remove since there is no other way to reference it. The two methods do the same exact thing, *except*, remove() will raise an error if the element you are trying to remove is not in the set while discard() will not.
+
+If **fruits** = {“apple”, “strawberry”, “banana”, “orange”}, then
+
+remove(“strawberry”)
+
+and
+
+discard(“strawberry”)
+
+will both give you fruits = **{“apple”, banana”, “orange”}**
+
+Finally, let’s address dictionaries. This data structure functions using a key-value pair which allows you to find an element given a key, such as a character or a string, rather than using a typical numerical index. Though this type of array is unordered, it is still addressable since you have a way of finding an element using its unique key.
+
+## Dictionaries
+
+**Initialization**
+
+*dictionary = {key1:value1, key2:value2}*
+
+Because of the way dictionaries are designed, you can use different data types as keys and values. We use curly brackets, {}, to define the dictionary, a colon, ‘:’, to assign a key to a value, and a comma, ‘,’, to separate entries.
+
+Ex: If we wanted to create a dictionary about a person with attributes “name”, “age”, and “college”, we could use the attribute names as keys and the personal attributes as values.
+
+my_dictionary = {“name” : “Danielle”,
+
+ “age” : 20,
+
+ “college” : “Binghamton University”
+
+ }
+
+Though you do not have to insert a new line and tab for each input, it may make initializing your dictionary easier to read.
+
+**Accessing an Element**
+
+*dictionary[key]*
+
+To get the value stored at a key, you use square brackets, [], just as you would with a list - except, this time you pass a key as the parameter rather than an index.
+
+Ex: my_dictionary[“name”] would return **“Danielle”**
+
+**Modifying an Element**
+
+*dictionary[key] = new_value*
+
+Similar to the way we update an element of a list, you would also use square brackets, [], and an equals sign, =, to update the value of a dictionary at a certain key. It should be noted that you can only update the value in a key-value pair – if you would like to update the key, you must create a new key-value pair and delete the old one.
+
+my_dictionary[“age”] = 21
+
+Now, my_dictionary would look like this:
+
+{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”}
+
+**Adding an Element**
+
+*dictionary[new_key] = new_value*
+
+The process of adding a new key-value pair to a dictionary is the same as that of updating an existing pair. The only difference is that the key in the square brackets is not expected to be in the dictionary. **This is where you need to keep in mind that keys are unique.** If you mistakenly pass a key that is already in the dictionary when you mean to pass a new one, no error will be thrown and the existing key’s value will be updated.
+
+Ex: If you wanted to add a phone number to my_dictionary, the statement would look like this:
+
+my_dictionary[“phone number”] = “(888)123-4567”
+
+Now, my_dictionary’s contents would be: **{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”, “phone number” = “(888)123-4567”}**
+
+ **Removing an Element**
+
+*dictionary.pop(key)*
+
+If you would like to delete a specific key-value pair, you would use the pop() function and pass the key as the parameter.
+
+Ex: If you wanted to remove the “college” key, you would call the following:
+
+my_dictionary.pop(“college”)
+
+Now, the dictionary would look like this:
+
+{name: Danielle, age: 21, phone number = (888)123-4567}
+
+## When to Use Which
+
+Now that we have laid out the basic functions of lists, sets, and dictionaries, we can differentiate the three and list out some scenarios in which you would use each. Let’s start by finding what they all have in common and what makes them unique.
+
+To the right is a Venn diagram that shows the differences and similarities between lists, sets, and dictionaries. As you can see, the only similarity they all share in functionality is storing data. This graph will help you narrow down your choice simply based on whether you need something indexable, modifiable, or if you need your variables to be unique.
+
+Now that we know what makes each data structure unique, let’s get into their features that will further assist you in your choice.
+
+
+
+**Lists**
+
+Because a list is ordered, it features functions such as *sort()*, which re-orders your list either alphanumerically or according to a given function, and *reverse()* which puts your list in the order opposite to what it is in now. It also has a method called *count()* which returns the amount of times a passed variable is found in the list. These features make lists useful for a dataset that you would want to arrange in a certain manner, especially if your data features duplicate values.
+
+**Sets**
+
+Though sets seem difficult to work with as they aren’t indexable, they can be quite useful. Python sets are similar to mathematical sets – they are unordered and have unique elements. Just as you can find the union and intersection of sets in math, you can also find the union and intersection of Python sets using the *union()* function and *intersection()* function respectively. Both methods can take several sets as parameters and return the resulting set. These two functions only scratch the surface of what Python sets are capable of – you can determine if a set is disjoint from another, if one set is a subset of another, and so much more. Therefore, this option useful if you plan to perform such operations on your datasets.
+
+**Dictionaries**
+
+Dictionaries give you the best of both worlds in sets and lists. They are indexable and keep your information organized with the key-value pair design. Dictionaries can also be nested so that the value that a key maps to is a dictionary rather than a number or a string. This data structure is best if you want to store several pieces of information about one item. A good example would be simulating a phone book or an address book. You could set each key to be a contact’s name and each value as their phone number or address. This problem could also be approached using a nested dictionary where each nested dictionary represents a contact with several key-value pairs to store more information on each of them.
+
+Overall, none of these data structures are better than another – each has their own qualities and capabilities that make them useful for a certain purpose. Hopefully by this point you have figured out which method is best for storing the information that you will be using in your Python program. Otherwise, I advise you pick one out and search for where you may run into a problem. To learn more about Python, visit bitproject.org or e-mail me at danzelo1@binghamton.edu.
+
+
From c57aa7ec18c08fd70e3f72b51b6a1169f9d17d8c Mon Sep 17 00:00:00 2001
From: kfan19 <67115109+kfan19@users.noreply.github.com>
Date: Tue, 21 Jul 2020 18:39:13 -0400
Subject: [PATCH 2/7] Update Storing_Data_in_Python.md
---
IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index db891c7..f97f0e4 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -1,8 +1,8 @@
# Storing Data in Python
-When we think about Python, we can think of tons of applications for our potential code; we can create a desktop application, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is learning to store pieces of data that will be useful to our program and, more importantly, deciding how we will store this data. Lists, sets, and dictionaries are the most common ways to store data and, in this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.
+When we think about Python, we can think of tons of applications for our potential code; we can create desktop applications, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is to learn to store pieces of data that will be useful to our program and, more importantly, decide how we will store this data. Lists, sets, and dictionaries are the most common ways to store data. In this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.
-The first data structure I will talk about is probably the most commonly used in Python - lists. With this method, you can store variables of the same type in a specific order and access and modify them using an index.
+The first data structure I will talk about is probably the most commonly used in Python - lists. With this method, you can store variables of the same type in a specific order. The, you can access and modify them with an index.
## Lists
From 98de969665b6adcb6ac6605da4ca4d0be717b400 Mon Sep 17 00:00:00 2001
From: kfan19 <67115109+kfan19@users.noreply.github.com>
Date: Tue, 21 Jul 2020 22:18:49 -0400
Subject: [PATCH 3/7] First Edits
Mostly just split some long sentences into two.
---
.../Storing_Data_In_Python/Storing_Data_in_Python.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index f97f0e4..54fa7f8 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -24,7 +24,7 @@ If we wanted **numbers** initialized to be empty, its declaration would look lik
*list[index]*
-Quite possibly the most important thing to keep in mind when using a Python list is how indices are numbered. When we count in programming, we always start at 0, not 1. So, when we keep track of the index of a list, the first index is always numbered ‘0’. This means that if your list has six elements, the last element is stored at index ‘5’.
+The most important thing to keep in mind when using a Python list is how indices are numbered. When we count in programming, we always start at 0, not 1. When we keep track of the index of a list, the first index is always numbered ‘0’. This means that if your list has six elements, the last element is stored at index ‘5’.
With that being said, we can access an element using square brackets, [], and its index.
@@ -32,7 +32,7 @@ Ex: If we want to access the fourth element (index 3) and save it to a variable
x = numbers[3]
-“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that you are assigning a value to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. We are not modifying the variable on the right at all. So, in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
+“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that you are assigning a value to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. We are not modifying the variable on the right at all. Therefore in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
**Modifying an Element**
@@ -228,11 +228,11 @@ Now, the dictionary would look like this:
## When to Use Which
-Now that we have laid out the basic functions of lists, sets, and dictionaries, we can differentiate the three and list out some scenarios in which you would use each. Let’s start by finding what they all have in common and what makes them unique.
+Now that we have laid out the basic functions of lists, sets, and dictionaries, we can differentiate the three and list out some scenarios to use each one. First, let's find what they all have in common and what makes them unique.
To the right is a Venn diagram that shows the differences and similarities between lists, sets, and dictionaries. As you can see, the only similarity they all share in functionality is storing data. This graph will help you narrow down your choice simply based on whether you need something indexable, modifiable, or if you need your variables to be unique.
-Now that we know what makes each data structure unique, let’s get into their features that will further assist you in your choice.
+Now that we know what makes each data structure unique, let’s get into features that will further assist you in your choice.

@@ -246,8 +246,8 @@ Though sets seem difficult to work with as they aren’t indexable, they can be
**Dictionaries**
-Dictionaries give you the best of both worlds in sets and lists. They are indexable and keep your information organized with the key-value pair design. Dictionaries can also be nested so that the value that a key maps to is a dictionary rather than a number or a string. This data structure is best if you want to store several pieces of information about one item. A good example would be simulating a phone book or an address book. You could set each key to be a contact’s name and each value as their phone number or address. This problem could also be approached using a nested dictionary where each nested dictionary represents a contact with several key-value pairs to store more information on each of them.
+Dictionaries give you the best of both sets and lists. They are indexable and keep your information organized with the key-value pair design. Dictionaries can also be nested so that the value that a key maps to is a dictionary rather than a number or a string. This data structure is best if you want to store several pieces of information about one item. A good example would be simulating a phone book or an address book. You could set each key to be a contact’s name and each value as their phone number or address. This problem could also be approached using a nested dictionary where each nested dictionary represents a contact with several key-value pairs to store more information on each of them.
-Overall, none of these data structures are better than another – each has their own qualities and capabilities that make them useful for a certain purpose. Hopefully by this point you have figured out which method is best for storing the information that you will be using in your Python program. Otherwise, I advise you pick one out and search for where you may run into a problem. To learn more about Python, visit bitproject.org or e-mail me at danzelo1@binghamton.edu.
+Overall, none of these data structures are better than another – each has their own qualities and capabilities that make them useful for a certain purpose. Hopefully you have figured out which method is best for storing the information that you will be using in your Python program. Otherwise, I advise you pick one out and search for where you may run into a problem. To learn more about Python, visit bitproject.org or e-mail me at danzelo1@binghamton.edu.
From d601886a14c4e69d7ee2f7dddda84f009f66f3f0 Mon Sep 17 00:00:00 2001
From: Danielle Anzelone <32557138+danzelo1@users.noreply.github.com>
Date: Thu, 23 Jul 2020 15:44:48 -0400
Subject: [PATCH 4/7] Update Storing_Data_in_Python.md
Made changes in correspondence with Kelly's comments
---
.../Storing_Data_in_Python.md | 52 +++++++++----------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index 54fa7f8..6f50524 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -1,12 +1,12 @@
# Storing Data in Python
-When we think about Python, we can think of tons of applications for our potential code; we can create desktop applications, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is to learn to store pieces of data that will be useful to our program and, more importantly, decide how we will store this data. Lists, sets, and dictionaries are the most common ways to store data. In this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.
+Python has the ability to produce useful applications for our potential code; we can create desktop applications, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is to learn to store pieces of data that will be useful to our program and, more importantly, decide how we will store this data. Lists, sets, and dictionaries are the most common ways to store data. In this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.
The first data structure I will talk about is probably the most commonly used in Python - lists. With this method, you can store variables of the same type in a specific order. The, you can access and modify them with an index.
## Lists
-**Initialization**
+### Initialization
*list= [element1, element2, …, elementn]*
@@ -20,21 +20,21 @@ If we wanted **numbers** initialized to be empty, its declaration would look lik
numbers = []
-**Accessing an Element**
+### Accessing an Element
*list[index]*
The most important thing to keep in mind when using a Python list is how indices are numbered. When we count in programming, we always start at 0, not 1. When we keep track of the index of a list, the first index is always numbered ‘0’. This means that if your list has six elements, the last element is stored at index ‘5’.
-With that being said, we can access an element using square brackets, [], and its index.
+With that being said, we can access an element through the use of square brackets, [], and its index.
Ex: If we want to access the fourth element (index 3) and save it to a variable **x**, we would call:
x = numbers[3]
-“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that you are assigning a value to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. We are not modifying the variable on the right at all. Therefore in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
+“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that a value is being assigned to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. The variable on the right is not modified at all. Therefore in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
-**Modifying an Element**
+### Modifying an Element
*list[index] = new element*
@@ -44,9 +44,9 @@ Ex: If we wanted to change the third value of the list (index 2) to 10, we would
numbers[2] = 10
-The “numbers[2]” accesses the list at index 2 using the brackets, []. By putting an equals sign, “=”, to the right of it, we are indicating that we want to reassign numbers[2]’s value to the value on the right of the “=” – in this instance, it is 10.
+The “numbers[2]” accesses the list at index 2 using the brackets, []. Placing an equals sign, “=”, to the right of it indicates that we want to reassign numbers[2]’s value to the value on the right of the “=” – in this instance, it is 10.
-**Adding an Element**
+### Adding an Element
*append(new_element)*
@@ -74,7 +74,7 @@ Now the contents of numbers is: **[0, 1, 2, 3, 4, ‘a’, ‘b’, ‘c]**
Because of how Python is designed, if we insert an element at an index, the list automatically expands and shifts all the elements to the right of the given index one position to the right.
-**Removing an Element**
+### Removing an Element
*pop(index)*
@@ -102,9 +102,9 @@ Which would result in the list: **[“apple”, “strawberry”, “banana”]*
The next method for storing data that we will go over is sets. Sets allow you to store variables of the same type in a group – however, a set is unordered and each element must be unique.
- ## Sets
+## Sets
-**Initialization**
+### Initialization
*set = {element1, element2, …, elementn}*
@@ -114,15 +114,15 @@ Similar to a list, you can initialize a set to be empty, or you can add elements
fruit = {}
-**Accessing an Element**
+### Accessing an Element
Since sets are unordered and do not have indices, you cannot access a specific item in it as you would in a list.
- **Modifying an Element**
+### Modifying an Element
Unfortunately, once an item is added to a set, it cannot be modified, only removed. This is because there is no way to access the element to modify it since there are no indices.
-**Adding an Element**
+### Adding an Element
*set.add(new_element)*
@@ -140,7 +140,7 @@ You can also append multiple items at once using update() by passing several ele
Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”, “pineapple”, “mango”}**
-**Removing an Element**
+### Removing an Element
*set.remove(element)*
@@ -162,7 +162,7 @@ Finally, let’s address dictionaries. This data structure functions using a key
## Dictionaries
-**Initialization**
+### Initialization
*dictionary = {key1:value1, key2:value2}*
@@ -178,9 +178,9 @@ my_dictionary = {“name” : “Danielle”,
}
-Though you do not have to insert a new line and tab for each input, it may make initializing your dictionary easier to read.
+Though you do not have to insert a new line and tab for each input, it may make your dictionary easier to read.
-**Accessing an Element**
+### Accessing an Element
*dictionary[key]*
@@ -188,7 +188,7 @@ To get the value stored at a key, you use square brackets, [], just as you would
Ex: my_dictionary[“name”] would return **“Danielle”**
-**Modifying an Element**
+### Modifying an Element
*dictionary[key] = new_value*
@@ -200,11 +200,11 @@ Now, my_dictionary would look like this:
{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”}
-**Adding an Element**
+### Adding an Element
*dictionary[new_key] = new_value*
-The process of adding a new key-value pair to a dictionary is the same as that of updating an existing pair. The only difference is that the key in the square brackets is not expected to be in the dictionary. **This is where you need to keep in mind that keys are unique.** If you mistakenly pass a key that is already in the dictionary when you mean to pass a new one, no error will be thrown and the existing key’s value will be updated.
+The way in which you add a new key-value pair to a dictionary is the same as how you would update an existing pair. The only difference is that the key in the square brackets is not expected to be in the dictionary. **This is where you need to keep in mind that keys are unique.** If you mistakenly pass a key that is already in the dictionary when you mean to pass a new one, no error will be thrown and the existing key’s value will be updated.
Ex: If you wanted to add a phone number to my_dictionary, the statement would look like this:
@@ -212,7 +212,7 @@ Ex: If you wanted to add a phone number to my_dictionary, the statement would lo
Now, my_dictionary’s contents would be: **{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”, “phone number” = “(888)123-4567”}**
- **Removing an Element**
+### Removing an Element
*dictionary.pop(key)*
@@ -236,17 +236,17 @@ Now that we know what makes each data structure unique, let’s get into feature

-**Lists**
+#### Lists
Because a list is ordered, it features functions such as *sort()*, which re-orders your list either alphanumerically or according to a given function, and *reverse()* which puts your list in the order opposite to what it is in now. It also has a method called *count()* which returns the amount of times a passed variable is found in the list. These features make lists useful for a dataset that you would want to arrange in a certain manner, especially if your data features duplicate values.
-**Sets**
+#### Sets
Though sets seem difficult to work with as they aren’t indexable, they can be quite useful. Python sets are similar to mathematical sets – they are unordered and have unique elements. Just as you can find the union and intersection of sets in math, you can also find the union and intersection of Python sets using the *union()* function and *intersection()* function respectively. Both methods can take several sets as parameters and return the resulting set. These two functions only scratch the surface of what Python sets are capable of – you can determine if a set is disjoint from another, if one set is a subset of another, and so much more. Therefore, this option useful if you plan to perform such operations on your datasets.
-**Dictionaries**
+#### Dictionaries
-Dictionaries give you the best of both sets and lists. They are indexable and keep your information organized with the key-value pair design. Dictionaries can also be nested so that the value that a key maps to is a dictionary rather than a number or a string. This data structure is best if you want to store several pieces of information about one item. A good example would be simulating a phone book or an address book. You could set each key to be a contact’s name and each value as their phone number or address. This problem could also be approached using a nested dictionary where each nested dictionary represents a contact with several key-value pairs to store more information on each of them.
+Dictionaries give you the best of both sets and lists. They are indexable and keep your information organized with the key-value pair design. Dictionaries can also be nested so that the value that a key maps to is a dictionary rather than a number or a string. This data structure is best if you want to store several pieces of information about one item. A good example would be if you were to simulate a phone book or an address book. You could set each key to be a contact’s name and each value as their phone number or address. This problem could also be approached using a nested dictionary where each nested dictionary represents a contact with several key-value pairs to store more information on each of them.
Overall, none of these data structures are better than another – each has their own qualities and capabilities that make them useful for a certain purpose. Hopefully you have figured out which method is best for storing the information that you will be using in your Python program. Otherwise, I advise you pick one out and search for where you may run into a problem. To learn more about Python, visit bitproject.org or e-mail me at danzelo1@binghamton.edu.
From 3f99a2f9be6227f30810b0c99675645c8910e987 Mon Sep 17 00:00:00 2001
From: Danielle Anzelone <32557138+danzelo1@users.noreply.github.com>
Date: Sun, 26 Jul 2020 19:23:17 -0400
Subject: [PATCH 5/7] Update Storing_Data_in_Python.md
fixed image and changed the code snippets to look more like code. I feel like the image is still kinda big but i'm having trouble resizing it
---
.../Storing_Data_in_Python.md | 64 +++++++++----------
1 file changed, 29 insertions(+), 35 deletions(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index 6f50524..a6295bd 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -14,11 +14,11 @@ When you initialize a list, you must give it a name. If you choose to add elemen
Ex: Take a list of integers called **numbers**. Let’s suppose you want it to contain numbers 0-4. This is how we would initialize the list:
-numbers = [0, 1, 2, 3, 4]
+ numbers = [0, 1, 2, 3, 4]
If we wanted **numbers** initialized to be empty, its declaration would look like this:
-numbers = []
+ numbers = []
### Accessing an Element
@@ -30,7 +30,7 @@ With that being said, we can access an element through the use of square bracket
Ex: If we want to access the fourth element (index 3) and save it to a variable **x**, we would call:
-x = numbers[3]
+ x = numbers[3]
“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that a value is being assigned to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. The variable on the right is not modified at all. Therefore in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
@@ -42,7 +42,7 @@ Just as we can access an element and assign its value to a variable (like we did
Ex: If we wanted to change the third value of the list (index 2) to 10, we would call the following:
-numbers[2] = 10
+ numbers[2] = 10
The “numbers[2]” accesses the list at index 2 using the brackets, []. Placing an equals sign, “=”, to the right of it indicates that we want to reassign numbers[2]’s value to the value on the right of the “=” – in this instance, it is 10.
@@ -56,19 +56,18 @@ Say we want to add the number ‘5’ to our **numbers** list. If we had a speci
Ex: If we wanted to place 5 at index 2, we would use the following statement:
- numbers.insert(5, 2)
+ numbers.insert(5, 2)
Now, the contents of numbers is: **[0, 1, 2, 3, 4, 5]**. However, if we wanted to tack ‘5’ onto the end of the list, we would simply use the append() function and pass 5 as a parameter.
-numbers.append(5)
+ numbers.append(5)
Here, the contents of numbers is: **[0, 1, 2, 3, 4, 5]**
The append() function is very user-friendly because it lets you append list onto one another.
-letters = [‘a’, ‘b’, ‘c’]
-
-numbers.append(letters)
+ letters = [‘a’, ‘b’, ‘c’]
+ numbers.append(letters)
Now the contents of numbers is: **[0, 1, 2, 3, 4, ‘a’, ‘b’, ‘c]**
@@ -84,7 +83,7 @@ There are two ways in which we can remove an element - according to its index or
Ex: If we wanted to remove the fifth element (index 4) of our original list, we would call:
-numbers.pop(4)
+ numbers.pop(4)
Now the contents of numbers is: **[0, 1, 2, 3]**
@@ -96,7 +95,7 @@ Let’s define a list called **fruits** where fruits = **[“apple”, “strawb
If we wanted to remove “orange” from the list, we would call
-fruits.remove(“orange”)
+ fruits.remove(“orange”)
Which would result in the list: **[“apple”, “strawberry”, “banana”]**
@@ -110,9 +109,8 @@ The next method for storing data that we will go over is sets. Sets allow you to
Similar to a list, you can initialize a set to be empty, or you can add elements. However, with a set, we use curly brackets, {}, instead of square brackets, [], to initialize its values.
-Ex: fruit = {“apple”, “strawberry”, “banana”}
-
-fruit = {}
+ Ex: fruit = {“apple”, “strawberry”, “banana”}
+ fruit = {}
### Accessing an Element
@@ -130,13 +128,13 @@ Unfortunately, once an item is added to a set, it cannot be modified, only remov
Sets have an add() function that takes a variable of the same type as the rest of the set and appends it to the set. Since sets are unordered, there is no need to worry about where you should place it like you would when adding an item to a list.
-Ex: fruits.add(“orange”)
+ Ex: fruits.add(“orange”)
Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”}**
You can also append multiple items at once using update() by passing several elements.
-Ex:fruits.add([“orange”, “pineapple”, “mango”])
+ Ex:fruits.add([“orange”, “pineapple”, “mango”])
Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”, “pineapple”, “mango”}**
@@ -150,11 +148,9 @@ There are two functions that you may use to remove an element from a set. Both r
If **fruits** = {“apple”, “strawberry”, “banana”, “orange”}, then
-remove(“strawberry”)
-
-and
-
-discard(“strawberry”)
+ remove(“strawberry”)
+ and
+ discard(“strawberry”)
will both give you fruits = **{“apple”, banana”, “orange”}**
@@ -170,13 +166,10 @@ Because of the way dictionaries are designed, you can use different data types a
Ex: If we wanted to create a dictionary about a person with attributes “name”, “age”, and “college”, we could use the attribute names as keys and the personal attributes as values.
-my_dictionary = {“name” : “Danielle”,
-
- “age” : 20,
-
- “college” : “Binghamton University”
-
- }
+ my_dictionary = {“name” : “Danielle”,
+ “age” : 20,
+ “college” : “Binghamton University"
+ }
Though you do not have to insert a new line and tab for each input, it may make your dictionary easier to read.
@@ -194,11 +187,11 @@ Ex: my_dictionary[“name”] would return **“Danielle”**
Similar to the way we update an element of a list, you would also use square brackets, [], and an equals sign, =, to update the value of a dictionary at a certain key. It should be noted that you can only update the value in a key-value pair – if you would like to update the key, you must create a new key-value pair and delete the old one.
-my_dictionary[“age”] = 21
+ my_dictionary[“age”] = 21
Now, my_dictionary would look like this:
-{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”}
+ {“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”}
### Adding an Element
@@ -208,7 +201,7 @@ The way in which you add a new key-value pair to a dictionary is the same as how
Ex: If you wanted to add a phone number to my_dictionary, the statement would look like this:
-my_dictionary[“phone number”] = “(888)123-4567”
+ my_dictionary[“phone number”] = “(888)123-4567”
Now, my_dictionary’s contents would be: **{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”, “phone number” = “(888)123-4567”}**
@@ -220,21 +213,22 @@ If you would like to delete a specific key-value pair, you would use the pop() f
Ex: If you wanted to remove the “college” key, you would call the following:
-my_dictionary.pop(“college”)
+ my_dictionary.pop(“college”)
Now, the dictionary would look like this:
-{name: Danielle, age: 21, phone number = (888)123-4567}
+ {name: Danielle, age: 21, phone number = (888)123-4567}
## When to Use Which
Now that we have laid out the basic functions of lists, sets, and dictionaries, we can differentiate the three and list out some scenarios to use each one. First, let's find what they all have in common and what makes them unique.
-To the right is a Venn diagram that shows the differences and similarities between lists, sets, and dictionaries. As you can see, the only similarity they all share in functionality is storing data. This graph will help you narrow down your choice simply based on whether you need something indexable, modifiable, or if you need your variables to be unique.
+Below is a Venn diagram that shows the differences and similarities between lists, sets, and dictionaries. As you can see, the only similarity they all share in functionality is storing data. This graph will help you narrow down your choice simply based on whether you need something indexable, modifiable, or if you need your variables to be unique.
Now that we know what makes each data structure unique, let’s get into features that will further assist you in your choice.
-
+
+
#### Lists
From d76a14af3ca919acc3b594bfbf5a649c5536929b Mon Sep 17 00:00:00 2001
From: Danielle Anzelone <32557138+danzelo1@users.noreply.github.com>
Date: Sun, 26 Jul 2020 19:31:57 -0400
Subject: [PATCH 6/7] fixing headlines
---
.../Storing_Data_in_Python.md | 24 +++++++++----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index a6295bd..78f034a 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -20,7 +20,7 @@ If we wanted **numbers** initialized to be empty, its declaration would look lik
numbers = []
-### Accessing an Element
+### Access an Element
*list[index]*
@@ -34,7 +34,7 @@ Ex: If we want to access the fourth element (index 3) and save it to a variable
“x =” assigns the value of x and “numbers[3]” returns the item at the third index of the list. If you are new to coding, you should keep in mind that **“=” does not indicate an equivalence relation, it means that a value is being assigned to the variable on the left.** Looking at the example above, we can say that *x is numbers[3]* or *x is 3*, BUT, we CANNOT say that *numbers[3] = x*. The variable on the right is not modified at all. Therefore in this case, although we change what ‘x’ means, the value of numbers[3] remains the same.
-### Modifying an Element
+### Modify an Element
*list[index] = new element*
@@ -46,7 +46,7 @@ Ex: If we wanted to change the third value of the list (index 2) to 10, we would
The “numbers[2]” accesses the list at index 2 using the brackets, []. Placing an equals sign, “=”, to the right of it indicates that we want to reassign numbers[2]’s value to the value on the right of the “=” – in this instance, it is 10.
-### Adding an Element
+### Add an Element
*append(new_element)*
@@ -73,7 +73,7 @@ Now the contents of numbers is: **[0, 1, 2, 3, 4, ‘a’, ‘b’, ‘c]**
Because of how Python is designed, if we insert an element at an index, the list automatically expands and shifts all the elements to the right of the given index one position to the right.
-### Removing an Element
+### Remove an Element
*pop(index)*
@@ -112,15 +112,15 @@ Similar to a list, you can initialize a set to be empty, or you can add elements
Ex: fruit = {“apple”, “strawberry”, “banana”}
fruit = {}
-### Accessing an Element
+### Access an Element
Since sets are unordered and do not have indices, you cannot access a specific item in it as you would in a list.
-### Modifying an Element
+### Modify an Element
Unfortunately, once an item is added to a set, it cannot be modified, only removed. This is because there is no way to access the element to modify it since there are no indices.
-### Adding an Element
+### Add an Element
*set.add(new_element)*
@@ -138,7 +138,7 @@ You can also append multiple items at once using update() by passing several ele
Now the contents of fruits is: **{“apple”, “strawberry”, “banana”, “orange”, “pineapple”, “mango”}**
-### Removing an Element
+### Remove an Element
*set.remove(element)*
@@ -173,7 +173,7 @@ Ex: If we wanted to create a dictionary about a person with attributes “name
Though you do not have to insert a new line and tab for each input, it may make your dictionary easier to read.
-### Accessing an Element
+### Access an Element
*dictionary[key]*
@@ -181,7 +181,7 @@ To get the value stored at a key, you use square brackets, [], just as you would
Ex: my_dictionary[“name”] would return **“Danielle”**
-### Modifying an Element
+### Modify an Element
*dictionary[key] = new_value*
@@ -193,7 +193,7 @@ Now, my_dictionary would look like this:
{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”}
-### Adding an Element
+### Add an Element
*dictionary[new_key] = new_value*
@@ -205,7 +205,7 @@ Ex: If you wanted to add a phone number to my_dictionary, the statement would lo
Now, my_dictionary’s contents would be: **{“name”: “Danielle”, “age”: 21, “college”: “Binghamton University”, “phone number” = “(888)123-4567”}**
-### Removing an Element
+### Remove an Element
*dictionary.pop(key)*
From a76e8be5975119760f20ba9a7826fc502b8a196e Mon Sep 17 00:00:00 2001
From: Danielle Anzelone <32557138+danzelo1@users.noreply.github.com>
Date: Sun, 26 Jul 2020 19:32:17 -0400
Subject: [PATCH 7/7] fixing title
---
IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
index 78f034a..0fcb1d6 100644
--- a/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
+++ b/IMC_Python/Storing_Data_In_Python/Storing_Data_in_Python.md
@@ -1,4 +1,4 @@
-# Storing Data in Python
+# How to Store Data in Python
Python has the ability to produce useful applications for our potential code; we can create desktop applications, build websites, analyze data, and much more - the possibilities are endless. However, in order to do anything of that caliber with this programming language, you must start from the bottom and master the basics. One essential building block of Python is to learn to store pieces of data that will be useful to our program and, more importantly, decide how we will store this data. Lists, sets, and dictionaries are the most common ways to store data. In this blog post, I will show you how you can use them, why you would want to use them, and what features each data structure has to offer.