<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Overview
Hour 1
JSON
Regular Expressions
Hour 2
Q&A
Hour 3
Work Time
JSON Format
Strings can be further arranged, so they can encode more complex information. For example, CSV (Comma-Separated Values) can be used to share spreadsheet data between applications. 
JSON (Javascript Object Notation) is used to transmit ordered lists (arrays) and name-
value pairs (objects). It can be sent in a file or through a web request.
Syntax
The syntax for a JSON array is similar to the syntax for a Python list.
["Monday",  6, "pumpkin", 3.1415]
The quotation marks around strings are mandatory.
The syntax for a JSON objecgts is similar to the syntax for Python dictionaries.
`
        {
           "latitude_degree"
Step1:  Reading JSON
There are Python functions for encoding and decoding JSON into data structures.
Step2:  json_contents is typically list, a dictionary, or a combination. You already know how to use these. You can use a for to iterate over all the elements in a list. You can use dictionary syntax to access key value pairs.
Step3:  Regular Expressions
Regular expressions, called regexes for short, are descriptions for a pattern of text. These are useful for validating inputs and formatting.
For example, a \d in a regex stands for a digit character—that is, any single numeral 0 to 9. The regex \d\d\d-\d\d\d-\d\d\d\d is used by Python to match a telephone number as a string of three numbers, a hyphen, three more numbers, another hyphen, and four numbers. Any other string would not match the \d\d\d-\d\d\d-\d\d\d\d regex.
But regular expressions can be much more sophisticated. For example, adding a 3 in curly brackets ({3}) after a pattern is like saying, “Match this pattern three times.” So the slightly shorter regex \d{3}-\d{3}-\d{4} also matches the correct phone number format.
Resources
Chapter 7 of "Automate the Boring Stuff with Python
Step4:  Matching Regex Objects
Step5:  Search moves through the string from start to end, stopping at the first match found
All of the pattern must match
Grouping with Parentheses
Parentheses are used to groups parts of expression
Groups can be retrieve parts of the match
Step6:  Special Operators
^ = start, $ = end -- match the start or end of the string
\ -- inhibit the "specialness" of a character. So, for example, use . to match a period or \ to match a slash. If you are unsure if a character has special meaning, such as '@', you can put a slash in front of it, \@, to make sure it is treated just as a character.
| (pipe, on slash key) --alternation, for combinining patterns
? --optional matching
Step7:  Wildcard Characters
. (a period) -- matches any single character except newline '\n'
* (asterisk) -- match zero or more, or optional
+ -- match one or more
Step8:  Matching Specific Repetitions
Another way of writing (Ha)(Ha)(Ha) is (Ha){3}
Step9:  (Ha){3} means exactly 3 repetitions
(Ha){,5} means up to 5 repetitions
(Ha){3,5} means 3 to 5 repetitions
Python regular matching is greedy by default.
It takes the first match and makes it as long as possible.
In ambiguous situations, the longest string possible is matched.
To suppress this use a ? (question mark) after the pattern
Step10:  Character Classes
Another way of writing (0|1|2|3|4|5|6|7|8|9) is \d, which is a shorthand character class.
<img src="images/character_classes.png" width=600>
Step11:  Custom Character Classes
Use square brackets
Use a caret (^) to negate
It's on the 6 key
Step12:  Compilation Flags
DOTALL, S --Make . match any character, including newlines
IGNORECASE, I --Do case-insensitive matches
LOCALE, L --Do a locale-aware match
MULTILINE, M  --Multi-line matching, affecting ^ and $
VERBOSE, X    --Enable verbose REs, which can be organized more cleanly and understandably.
UNICODE, U    --Makes several escapes like \w, \b, \s and \d dependent on the Unicode character database.
<ASSISTANT_TASK:>
Python Code:
import json
list1 = ["Monday",  6, "pumpkin", 3.1415]
dict1 = {
           "latitude_degree": 43.6617, 
           "latitude_direction": "N",
           "longitude_degree": 79.3950, 
           "longitude_direction": "W"
        }
json_encoded = json.dumps(dict1)
print json_encoded
Explanation: Overview
Hour 1
JSON
Regular Expressions
Hour 2
Q&A
Hour 3
Work Time
JSON Format
Strings can be further arranged, so they can encode more complex information. For example, CSV (Comma-Separated Values) can be used to share spreadsheet data between applications. 
JSON (Javascript Object Notation) is used to transmit ordered lists (arrays) and name-
value pairs (objects). It can be sent in a file or through a web request.
Syntax
The syntax for a JSON array is similar to the syntax for a Python list.
["Monday",  6, "pumpkin", 3.1415]
The quotation marks around strings are mandatory.
The syntax for a JSON objecgts is similar to the syntax for Python dictionaries.
`
        {
           "latitude_degree": 43.6617, 
           "latitude_direction": "N",
           "longitude_degree": 79.3950, 
           "longitude_direction": "W"
        }
Arrays and objects can appear as values within arrays and objects. Here is an example of a complex JSON string, formatted for readability by humans.
[
 {
  "customer": {
   "last": "Ball", 
   "first": "Maldonado"
  }, 
  "rating": 2, 
  "specialOrder": true, 
  "tags": [
   "ullamco", 
   "aute", 
   "mollit", 
   "ex"
  ], 
  "greeting": "Happy Birthday", 
  "filling": "chocolate", 
  "batter": "vanilla", 
  "frosting": "chocolate"
 }
]
As you can see, it’s a customer dictionary with a nested dictionary for the address and a list of dictionaries for telephone numbers. The formatting is similar to Python.
An useful tool when working with JSON is a viewer. JSON that is being transmitted usually has all of the whitespace removed. It makes the total transmission smaller, but difficult for humans to read. It’s common to use a JSON viewer, in your IDE or on a web page. You can find one by Googling.
Another common tool is a JSON validator. It checks whether your syntax is correct and helps to
localize errors. Sometimes you can use the same tool to view and validate JSON.
Writing JSON
Any Python data structure can be saved as JSON.
End of explanation
import json
with open("cake.json", "r") as file_reader:
    file_contents = file_reader.read()
    
json_contents = json.loads(file_contents)
# print json_contents
print json.dumps(json_contents, indent=1)
Explanation: Reading JSON
There are Python functions for encoding and decoding JSON into data structures.
End of explanation
for order in json_contents:
    print("Customer: " + order['customer']['last'])
    for word in order['tags']:
        print("\t" + word)
Explanation: json_contents is typically list, a dictionary, or a combination. You already know how to use these. You can use a for to iterate over all the elements in a list. You can use dictionary syntax to access key value pairs.
End of explanation
import re
phone_regex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')
Explanation: Regular Expressions
Regular expressions, called regexes for short, are descriptions for a pattern of text. These are useful for validating inputs and formatting.
For example, a \d in a regex stands for a digit character—that is, any single numeral 0 to 9. The regex \d\d\d-\d\d\d-\d\d\d\d is used by Python to match a telephone number as a string of three numbers, a hyphen, three more numbers, another hyphen, and four numbers. Any other string would not match the \d\d\d-\d\d\d-\d\d\d\d regex.
But regular expressions can be much more sophisticated. For example, adding a 3 in curly brackets ({3}) after a pattern is like saying, “Match this pattern three times.” So the slightly shorter regex \d{3}-\d{3}-\d{4} also matches the correct phone number format.
Resources
Chapter 7 of "Automate the Boring Stuff with Python: Practical Programming for Total Beginners" by Al Sweigart. 
Python Regular Expressions by Google for Education
Creating Regex Objects
End of explanation
phone_match = phone_regex.search('My number is 647-970-9425.')
if phone_match is None:
    print ("No match found")
else:
    print('Phone number found: ' + phone_match.group())
    
Explanation: Matching Regex Objects
End of explanation
phone_regex = re.compile(r'(\d\d\d)-(\d\d\d-\d\d\d\d)')
phone_match = phone_regex.search('My number is 415-555-4242.')
print phone_match.group()
print phone_match.group(0)
print phone_match.group(1)
print phone_match.group(2)
print phone_match.groups()
area_code, main_number = phone_match.groups()
print area_code
print main_number
Explanation: Search moves through the string from start to end, stopping at the first match found
All of the pattern must match
Grouping with Parentheses
Parentheses are used to groups parts of expression
Groups can be retrieve parts of the match
End of explanation
cheese_regex = re.compile(r'^Cheese')
cheese_match = cheese_regex.search('Cheese Shop sketch')
print cheese_match.group()
cheese_match = cheese_regex.search('Not much of a Cheese Shop really, is it?')
cheese_match == None
monty_regex = re.compile(r"Terry|Michael|Graham|John|Eric")
monty_match = monty_regex.search("Eric Palin, John Cleese, and Eric Idle")
print monty_match.group(), "at" , monty_match.start()
monty_match = monty_regex.findall("Eric Palin, John Cleese, and Eric Idle")
print monty_match
parrot_regex = re.compile(r'Parrot(man|mobile|copter|bat)')
parrot_match = parrot_regex.search('Parrotcopter lost a blade')
parrot_match.group()
parrot_regex = re.compile(r'Parrot(wo)?man')
parrot_match = parrot_regex.search('The Adventures of Parrotman')
print parrot_match.group()
parrot_match = parrot_regex.search('The Adventures of Parrotwoman')
print parrot_match.group()
Explanation: Special Operators
^ = start, $ = end -- match the start or end of the string
\ -- inhibit the "specialness" of a character. So, for example, use . to match a period or \ to match a slash. If you are unsure if a character has special meaning, such as '@', you can put a slash in front of it, \@, to make sure it is treated just as a character.
| (pipe, on slash key) --alternation, for combinining patterns
? --optional matching
End of explanation
parrot_regex = re.compile(r'Parrot(wo)*man')
parrot_match = parrot_regex.search('The Adventures of Parrotman')
print parrot_matches.group()
parrot_match = parrot_regex.search('The Adventures of Parrotwowowoman')
print parrot_match.group()
parrot_regex = re.compile(r'Parrot(wo)+man')
parrot_match = parrot_regex.search('The Adventures of Parrotwoman')
print parrot_match.group()
parrot_match = parrot_regex.search('The Adventures of Parrotman')
parrot_match == None
# Match everything with .*
name_regex = re.compile(r'First Name: (.*) Last Name: (.*)')
name_match = name_regex.search("First Name: Tarquin Last Name: Fin-tim-lim-bim-whin-bim-lim-bus-stop-F'tang-F'tang-Ole-Biscuitbarrel")
name_match.groups()
Explanation: Wildcard Characters
. (a period) -- matches any single character except newline '\n'
* (asterisk) -- match zero or more, or optional
+ -- match one or more
End of explanation
ha_regex = re.compile(r'(Ha){3}')
ha_match = ha_regex.search('HaHaHa')
ha_match.group()
Explanation: Matching Specific Repetitions
Another way of writing (Ha)(Ha)(Ha) is (Ha){3}
End of explanation
greedy_regex = re.compile(r'(Ha){3,5}')
greedy_match = greedy_regex.search('HaHaHaHaHa')
print greedy_match.group()
nongreedy_regex = re.compile(r'(Ha){3,5}?')
nongreedy_match = nongreedy_regex.search('HaHaHaHaHa')
print nongreedy_match.group()
Explanation: (Ha){3} means exactly 3 repetitions
(Ha){,5} means up to 5 repetitions
(Ha){3,5} means 3 to 5 repetitions
Python regular matching is greedy by default.
It takes the first match and makes it as long as possible.
In ambiguous situations, the longest string possible is matched.
To suppress this use a ? (question mark) after the pattern
End of explanation
gbs_regex = re.compile(r'\d+\s\w+')
gbs_regex.findall("12 apostles, 11 went straight to heaven, \\
                 10 commandments, 9 bright eyed shiners, \\
                 8 Gabriel angels")
Explanation: Character Classes
Another way of writing (0|1|2|3|4|5|6|7|8|9) is \d, which is a shorthand character class.
<img src="images/character_classes.png" width=600>
End of explanation
vowel_regex = re.compile(r'[aeiouAEIOU]')
vowel_regex.findall('This is a dead parrot. DEAD.')
Explanation: Custom Character Classes
Use square brackets
Use a caret (^) to negate
It's on the 6 key
End of explanation
vowel_regex = re.compile(r'[aeiou]', re.I)
vowel_regex.findall('This is a dead parrot. DEAD.')
# Exercise
# Joke: What do you call a pig with three eyes? Piiig!
Explanation: Compilation Flags
DOTALL, S --Make . match any character, including newlines
IGNORECASE, I --Do case-insensitive matches
LOCALE, L --Do a locale-aware match
MULTILINE, M  --Multi-line matching, affecting ^ and $
VERBOSE, X    --Enable verbose REs, which can be organized more cleanly and understandably.
UNICODE, U    --Makes several escapes like \w, \b, \s and \d dependent on the Unicode character database.
End of explanation
<END_TASK>