<jupyter_start><jupyter_text>**Dictionaries****Within Python, the dictionary class is a collection of mutable objects (values) that are indexed by numbers, strings or certain sets (keys) which are immutable.****The main use of dictionaries is to store values which can then be called by a given key.** Source: [Python Data Structures and Algorithms](https://www.amazon.com/Python-Data-Structures-Algorithms-application-ebook/dp/B01IF7NLM8) by  <NAME><jupyter_code>help(dict)<jupyter_output>Help on class dict in module builtins:

class dict(object)
 |  dict() -> new empty dictionary
 |  dict(mapping) -> new dictionary initialized from a mapping object's
 |      (key, value) pairs
 |  dict(iterable) -> new dictionary initialized as if via:
 |      d = {}
 |      for k, v in iterable:
 |          d[k] = v
 |  dict(**kwargs) -> new dictionary initialized with the name=value pairs
 |      in the keyword argument list.  For example:  dict(one=1, two=2)
 |  
 |  Methods defined here:
 |  
 |  __contains__(self, key, /)
 |      True if the dictionary has the specified key, else False.
 |  
 |  __delitem__(self, key, /)
 |      Delete self[key].
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __getitem__(...)
 |      x.__getitem__(y) <==> x[y]
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __init__(self,[...]<jupyter_text>**Creating a Dictionary**<jupyter_code>#explicitly code it out
alpha_dict_1 = {1:'a', 2:'b', 3:'c', 4:'d'}
print(alpha_dict_1)

#calling the dict constructor
alpha_dict_2 = dict(zip([i for i in range(1,7)], [i for i in string.ascii_lowercase][:6]))
print(alpha_dict_2)

#dictionary comprehension
alpha_dict_3 = {alpha: num for alpha, num in zip(range(1,27), [i for i in string.ascii_lowercase])}
print(alpha_dict_3)

#empty dictionary
empty_dict = {}
print(empty_dict)<jupyter_output>{1: 'a', 2: 'b', 3: 'c', 4: 'd'}
{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f'}
{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i', 10: 'j', 11: 'k', 12: 'l', 13: 'm', 14: 'n', 15: 'o', 16: 'p', 17: 'q', 18: 'r', 19: 's', 20: 't', 21: 'u', 22: 'v', 23: 'w', 24: 'x', 25: 'y', 26: 'z'}
{}<jupyter_text>**Calling keys and values from a Dictionary**<jupyter_code>for key in alpha_dict_1:
  print(key)
for value in alpha_dict_1.values():
  print(value)
for key, value in alpha_dict_1.items():
  print(key, value)
alpha_dict_1[1]<jupyter_output><empty_output><jupyter_text>**Deleting and Popping Keys and Values from a Dictionary**<jupyter_code>alpha_dict_1
del alpha_dict_1[4]
#use pop if you need so save the value you are deleting
removed_letter = alpha_dict_1.pop(3)
removed_letter
alpha_dict_1<jupyter_output><empty_output><jupyter_text>**Changing values within a Dictionary**<jupyter_code>for key,upper in zip(alpha_dict_3, string.ascii_uppercase):
  alpha_dict_3[key] = upper
alpha_dict_3<jupyter_output><empty_output><jupyter_text>**Sorting a Dictionary**<jupyter_code>reverse_dict = dict(zip([key for key in alpha_dict_3], sorted(list(alpha_dict_3.values()),reverse = True)))
reverse_dict<jupyter_output><empty_output><jupyter_text>**Nested Dictionaries**<jupyter_code>students = {'Student 1': {'Name': 'Amir', 'Major': 'Computer Science', 'Student Class': 'Junior'},
            'Student 2': {'Name': 'John', 'Major': 'Finance', 'Student Class': 'Sophmore'},
            'Student 3': {'Name': 'Arjun', 'Major': 'Statistics', 'Student Class': 'Freshman'},
            'Student 4': {'Name': 'Mei', 'Major': 'Economics', 'Student Class': 'Senior'},
            'Student 5': {'Name': 'Helga', 'Major': 'Physics', 'Student Class': 'Sophmore'}}
students['Student 1'].get('Name')
statistics_midterm = {'Student Name':['Amir', 'John', 'Arjun', 'Mei', 'Helga'],
                       'Score':[85, 55, 72, 90, 70]}<jupyter_output><empty_output><jupyter_text>**Create a pandas DataFrame from a Dictionary**<jupyter_code>stats_midterm = pd.DataFrame(data = statistics_midterm)
stats_midterm<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17070217917675545, 'fraction_numerical': 0.025907990314769976, 'mean_word_length': 4.682255845942229, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '184596', 'license': 'MIT', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1483, 'n_words': 404, 'path': 'Python YouTube Tutorials/Python_Dictionaries!.ipynb', 'repo_name': 'tudev/Workshops-2020-2021', 'size': '4137'}