<jupyter_start><jupyter_text>Dictionaries---A **dictionary** is a collection of dissimilar data stored together in one *record*. Each item of data has a  (or key) that describes its paired value.  Create a dictionary object by declaring the set of keys and values, e.g.:```   transport = {       "type":"bus",       "numPassengers":72,       "colour":"blue",       "fuel":"diesel"   }```To access a value in a dictionary, use its key:  ```transport["type"] = "coach"transport_type = transport["type"]transport_colour = transport["colour"]transport["fuel"] = petrol```To add a new key/value pair to a dictionary, simply assign a value to a new key:  ```transport["seats"] = 54```The transport dictionary will now look like this:  ```   transport = {       "type":"bus",       "numPassengers":72,       "colour":"blue",       "fuel":"diesel",       "seats":54   }``` --- Exercise 1 - print dictionaryWrite a function which will:  *  create an empty dictionary for a person (name, age and postcode, with values "", 0 and "")*  ask the user for name, age and postcode and assign the values to the correct keys in the dictionary  *  print the dictionaryTest input:  <NAME>  16  AB5 3DF  Expected output:  ["name":"<NAME>", "age":16, "postcode":"AB5 3DF"]<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 2 - create a dictionaryWrite a function that will create two dictionaries,without values:  1.  person (with keys firstname, surname, birthdate, postcode)  2.  car (with key/value pairs as follows:  make - Vauxhall, model - Corsa, engineSize - 1199, fuelType - unleaded, num_doors - 4)  *   ask the user to enter the values for the person dictionary  *   print, on one line, the person's name from the person dictionary and the make of the car from the car dictionary.Test input:  Jack  Jones  2005/02/02    AB5 3DF  Expected output:  <NAME> Vauxhall<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 3 - check dictionary valuesWrite a new function which will:*  set up the same two dictionaries as in Exercise 2  *  ask the user to enter the details to complete the person record  *  calculate the person's age  *  if the person is under 17 then print a message to say that they can't buy a car as they are too young to drive*  else if the person is under 25 then print a message to say that an engine size under 1200 is recommended  *  ask the user to enter the make of car that the person is looking for  *  if the user enters the same make as that stored in the car record, then print a message to say that you have one car of that make in stock and print all the details of the car that you have the record for*  else (if the user enters any other car make) then print a message to say sorry that you don't have any cars of that make in stock*  print a message to say that the user can get more details for stockist in the  area if they call 01234567890*  print a message to say "Thank you  for using our site"  Test input:  <NAME>  2005/02/02  AB5 3DF  Vauxhall  Expected output:  You are too young to driveTest input:  John  Jones  2003/02/02  AB5 3DF  Vauxhall Expected output:  An engine size under 1200 is recommended  We have one Vauxhall in stock, details:  Make - Vauxhall    Model - Corsa    Engine size - 1199  Fuel type - unleaded   Number of doors - 4  You can get more details of stockists near AB5 3DF on 01234567890  Thank you <NAME> for using our site.     Test input:  John  Jones  2003/02/02  AB5 3DF  Ford  Expected output:  An engine size under 1200 is recommended  Sorry, we don't have any of that make in stock<jupyter_code>from datetime import datetime, timedelta, date
def car():
  person = {
      "firstname": "",
      "surname":"",
      "birthdate": "",
      "postcode": ""
  }
  # person['firstname'] = input("firstname")
  # person['surname'] = input("surname")
  person['birthdate'] = input('birthday in yyyy/mm/dd')
  # person['postcode'] = input('postcode')

  car = {
      "make" : "Vauxhall", 
      "model" :"Corsa", 
      "engineSize" :1199, 
      "fuelType" :"unleaded", 
      "num_doors" : 4
  }

  birthdate = datetime.strptime(person['birthdate'], "%Y/%m/%d")
  now = date.today()
  age = now.year - birthdate.year
  if age <18:
    print("Sorry too young to drive")
  elif age > 17 and age < 25:
    print("engine size of 1200 recommened")
  if age > 17:
    make = input("what make")
    if make == car['make']:
      print("we have that in stock")
      print(car.items)
  


car()<jupyter_output>birthday in yyyy/mm/dd2002/02/02
20<jupyter_text>--- Exercise 4 - print keys and valuesTwo dictionaries have been created below.  You can print a list of the dictionary's keys using `dictionary_name.keys()` and the values using `dictionary_name.values()`Write a function which will accept a dictionary as a parameter and will:  *  print the dictionary keys as a list   *  print the dictionary values as a list  *Hint*:  you will need to cast the keys as a list (`list(dictionary_name.keys()`)  and do the same for the values.**Expected Output**Input: English  Output: ['Andy', 'Angela']  [95, 53]  Input: Maths  Output:  ['Andy', 'Angela']  [58, 72]<jupyter_code>def display_dictionary(scores):
  #  add your code below this line
  


english_scores = {'Andy': 95, 'Angela': 53}
maths_scores = {'Andy': 58, 'Angela': 72}
display_dictionary(english_scores)
display_dictionary(maths_scores)<jupyter_output><empty_output><jupyter_text>--- Exercise 5 - add fieldWrite a function which will:*  create a new dictionary called **science_scores** with values of 0 for both Andy and Angela*  update Andy's score for science to 73 and Angela's score to 73   *  create a new key/value pair by adding another learner to the `science_scores`  dictionary (George has a score of 55)    *  print the `science_scores` dictionary to check results  Expected Output{'Andy': 73, 'Angela': 73, 'George': 55}<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 6 - loop through keys/value pairsWrite a function which will use a *for* loop to print the each key/value pair in the science dictionary (recreate this dictionary in this function) *(Hint: you can iterate through the key/value pairs in the dictionary in the same way as you iterate through a loop (e.g. for record in dictionary) and print the record (which is the key) and its value)*Expected output:  Angela 72  Andy 72  George 55<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 7 - generate new dictionary  Write a functions which will:*  create a new dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys*  print the dictionaryExpected output:  {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 8 - colour dictionary  Write a function which will:  *  create a new dictionary record called colour_codes with the values 'red' - 'FF0000', 'green' - '008000', 'black' - '000000', 'white' - 'FFFFFF'*  add a new colour code:  'blue' - '0000FF'    *  remove the colours black and white from the dictionary  *Hint:  there is a list of methods [here](https://www.w3schools.com/python/python_ref_dictionary.asp)*<jupyter_code><jupyter_output><empty_output><jupyter_text>--- Exercise 9 - item tuples  Write a function which will:  *  create a new dictionary containing the colour codes for red, green, blue, black and white*  print the key/value pairs of a dictionary as a list of tuples  *Hint:  iterate through colours.items()*<jupyter_code>def dict_fun():
  colour_codes = {
      'red':'#FF0000',
      'green':'#008000' ,
      'blue': '#0000FF',
      'black':'#000000',
      'white':'#FFFFFF'
    }
  colours = []
  for items in colour_codes.items():
    colours.append(items)
  print(colours)

dict_fun()<jupyter_output>[('red', '#FF0000'), ('green', '#008000'), ('blue', '#0000FF'), ('black', '#000000'), ('white', '#FFFFFF')]<jupyter_text>--- Exercise 10 - check if emptyTaken from w3resouce.com  Write a function which will check if a dictionary is empty or not*Hint:  you can use bool(dictionary_name), if the dictionary is empty then bool(dictionary_name will be false)*Test 1 sample data:{}Expected output:Dictionary is empty  Test 2 sample data:  {"name":"Groucho", "occupation":"comedian"}Expected output:  Dictionary is not empty<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10463325038511671, 'fraction_numerical': 0.036023225500651734, 'mean_word_length': 4.056920311563811, 'pattern_counts': {'":': 18, '<': 46, '<?xml version=': 0, '>': 46, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '287916', 'license': 'CC0-1.0', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2473, 'n_words': 1083, 'path': 'Worksheet_Dictionaries_part_solutions.ipynb', 'repo_name': 'lilaceri/python-fundamentals', 'size': '8460'}