<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Recap 2
Second Checkpoint
Since the first recap, you've learned about lists, dictionaries and loops. Let's revise those concepts and how to use them in this notebook before continuing on to some new material. Answer the questions as best you can, working through any error messages you receive and remembering to refer back to previous notebooks. 
Lists
First, here's a reminder of some useful methods (i.e. functions) that apply to lists
Step1:  b) Replace the ??? so that it prints the position of Manchester in the list
Step2:  c) Replace the ??? so that it prints Belfast
Step3:  d) Use a negative index to print Belfast
Step4:  e) Force Python to generate a list index out of range error. NB
Step5:  f) Think about what the next line creates, then run the code.
Step6:  g) What would you change ??? to, to return [16.5, 13.4, 14.0]?
Step7:  h) What are two different ways of getting [15.2, 14.8] from the temperatures list?
Step8:  i) Notice that the list of temperatures is the same length as the list of cities, that's because these are (roughly) average temperatures for each city! Given this, how do you print
Step9:  Now copy+paste your code and change only one thing in order to print out
Step10:  1.2 Manipulating Multiple Lists
We'll create two lists for the next set of questions
Step11:  j) How do you get Python to print
Step12:  k) How to you get Python to print
Step13:  Let's re-set the lists (run the next code block)
Step14:  l) How would you print out
Step15:  m) How would you print out
Step16:  n) How would you print out [3, 2, 6, 5] with a permanent change to the list (not slicing)? NB
Step17:  Dictionaries
Remember that dictionaries (a.k.a. dicts) are like lists in that they are data structures containing multiple elements. A key difference between dictionaries and lists is that while elements in lists are ordered, dicts are unordered. This means that whereas for lists we use integers as indexes to access elements, in dictonaries we use 'keys' (which can multiple different types; strings, integers, etc.). Consequently, an important concept for dicts is that of key-value pairs. 
Creating an Atlas
Replace ??? in the following code block to make the code work as instructed in the comments. If you need some hints and reminders, revisit Code Camp Lesson 7.
Run the code and check you understand what the data structure that is being created (the data for each city are latitude, longitude and airport code)
Step18:  a) Add a record to the dictionary for Chennai (data here)
Step19:  b) In one line of code, print out the airport code for Chennai
Step20:  c) Check you understand the difference between the following two blocks of code by running them, checking the output and editing them (e.g. try the code again, but replacing Berlin with London)
Step21:  d) Adapting the code below, print out the city name and airport code for every city in our Atlas.
Step22:  Loops
Recall from the previous notebook that loops are a way to iterate (or repeat) chunks of code. The two most common ways to iterate a set of commands are the while loop and the for loop. 
Working with Loops
The questions below use for loops. Replace ??? in the following code block to make the code work as instructed in the comments. If you need some hints and reminders, revisit the previous notebook.
a) Print out the name and latitude of every city in the cities dictionary using a for loop
Step23:  b) Print out every city on a separate line using a for loop
Step24:  c) Now print using a loop this new data structure
<ASSISTANT_TASK:>
Python Code:
cities = ["Bristol", "London", "Manchester", "Edinburgh", "Belfast", "York"]
Explanation: Recap 2
Second Checkpoint
Since the first recap, you've learned about lists, dictionaries and loops. Let's revise those concepts and how to use them in this notebook before continuing on to some new material. Answer the questions as best you can, working through any error messages you receive and remembering to refer back to previous notebooks. 
Lists
First, here's a reminder of some useful methods (i.e. functions) that apply to lists:
| Method                 | Action |
|------------------------|------------------------------------------------------------------|
| list.count(x)        | Return the number of times x appears in the list                 |
| list.insert(i, x)  | Insert value x at a given position i                         |
| list.pop([i])        | Remove and return the value at position i (i is optional)    |
| list.remove(x)       | Remove the first element from the list whose value is x        |
| list.reverse()         | Reverse the elements of the list in place                        |
| list.sort()            | Sort the items of the list in place                              |
| list.index(x)        | Find the first occurence of x in the list                      |
| list[x:y]              | Subset the list from index x to y-1                          |
Interacting with Lists
Replace ??? in the following code blocks to make the code work as instructed in the comments. All of the methods that you need are listed above, so this is about testing yourself on your understanding both of how to read the help and how to index elements in a list.
a) The next line creates a list of city names (each element is a string) - run the code and check you understand what it is doing.
End of explanation
print("The position of Manchester in the list is: " + str(cities.???('Manchester')))
print("The position of Manchester in the list is: " + str(cities.index('Manchester')))
Explanation: b) Replace the ??? so that it prints the position of Manchester in the list
End of explanation
print(cities[2 + ???])
print(cities[2 + 2])
Explanation: c) Replace the ??? so that it prints Belfast
End of explanation
print(cities[???])
print(cities[-2])
Explanation: d) Use a negative index to print Belfast
End of explanation
print(cities[???])
print(cities[6]) #anything above five would do it
Explanation: e) Force Python to generate a list index out of range error. NB: This error happens you provide an index for which a list element does not exist
End of explanation
temperatures = [15.6, 16.5, 13.4, 14.0, 15.2, 14.8]
Explanation: f) Think about what the next line creates, then run the code.
End of explanation
print(temperatures[???])
print(temperatures[1:4])
Explanation: g) What would you change ??? to, to return [16.5, 13.4, 14.0]?
End of explanation
print(temperatures[???])
print(temperatures[???])
print(temperatures[4:6])
print(temperatures[-3:-1])
Explanation: h) What are two different ways of getting [15.2, 14.8] from the temperatures list?
End of explanation
city="Manchester" # Use this to start the solution...
#your code here
city="Manchester" # Use this to get the solution...
index = cities.index(city)
print("The average temperature in " + cities[index] + " is " + str(temperatures[index]) + " degrees.")
Explanation: i) Notice that the list of temperatures is the same length as the list of cities, that's because these are (roughly) average temperatures for each city! Given this, how do you print: "The average temperature in Manchester is 13.4 degrees." without doing any of the following:
1. Using a list index directly (i.e. cities[2] and temperatures[2]) or 
2. Hard-coding the name of the city? 
To put it another way, neither of these solutions is the answer:
python
print("The average temperature in Manchester is " + str(temperatures[2]) + " degrees.")
or 
python
city=2
print("The average temperature in " + cities[city] + " is " + str(temperatures[city]) + " degrees.")
Hint: you need to combine some of the ideas we've used above!
End of explanation
???
city="Belfast"
index = cities.index(city)
print("The average temperature in " + cities[index] + " is " + str(temperatures[index]) + " degrees.")
Explanation: Now copy+paste your code and change only one thing in order to print out: "The average temperature in Belfast is 15.2 degrees"
End of explanation
list1 = [1, 2, 3]
list2 = [4, 5, 6]
Explanation: 1.2 Manipulating Multiple Lists
We'll create two lists for the next set of questions
End of explanation
print( ??? )
print ( list1 + list2 )
Explanation: j) How do you get Python to print: [1, 2, 3, 4, 5, 6]
End of explanation
print( ??? )
print( list1+[list2])
Explanation: k) How to you get Python to print: [1, 2, 3, [4, 5, 6]]
End of explanation
list1 = [1, 2, 3]
list2 = [4, 5, 6]
Explanation: Let's re-set the lists (run the next code block)
End of explanation
list3 = ???
list3.???
print(list3)
list3 = list1+list2
list3.reverse()
print(list3)
Explanation: l) How would you print out: [6, 5, 4, 3, 2, 1] ?
End of explanation
list1.???
list2.???
print( list1+list2 )
list1.reverse()
list2.reverse()
print( list1+list2 )
Explanation: m) How would you print out: [3, 2, 1, 6, 5, 4] ?
End of explanation
list1.???
list2.???
print( list1+list2 )
list1.remove(1)
list2.remove(4)
print( list1+list2 )
Explanation: n) How would you print out [3, 2, 6, 5] with a permanent change to the list (not slicing)? NB: this follows on from the previous question, so note that the order is still 'reversed'.
End of explanation
cities = {
    'San Francisco': [37.77, -122.43, 'SFO'],
    'London': [51.51, -0.08, 'LDN'],
    'Paris': [48.86,2.29, 'PAR'],
    'Beijing': [39.92,116.40 ,'BEI'],
}
Explanation: Dictionaries
Remember that dictionaries (a.k.a. dicts) are like lists in that they are data structures containing multiple elements. A key difference between dictionaries and lists is that while elements in lists are ordered, dicts are unordered. This means that whereas for lists we use integers as indexes to access elements, in dictonaries we use 'keys' (which can multiple different types; strings, integers, etc.). Consequently, an important concept for dicts is that of key-value pairs. 
Creating an Atlas
Replace ??? in the following code block to make the code work as instructed in the comments. If you need some hints and reminders, revisit Code Camp Lesson 7.
Run the code and check you understand what the data structure that is being created (the data for each city are latitude, longitude and airport code)
End of explanation
cities = ???
cities = {
    'San Francisco': [37.77, -122.43, 'SFO'],
    'London': [51.51, -0.08, 'LDN'],
    'Paris': [48.86,2.29, 'PAR'],
    'Beijing': [39.92,116.40 ,'BEI'],
    'Chennai': [13.08, 80.27,'MAA']
}
Explanation: a) Add a record to the dictionary for Chennai (data here)
End of explanation
print(???)
print("The airport code for Chennai is " + cities["Chennai"][2])
Explanation: b) In one line of code, print out the airport code for Chennai
End of explanation
print(cities['Berlin'])
print(cities.get('Berlin'))
#Berlin is not in the dict. 
#The first code block above returns an error because Berlin is missing
#The second does not because it uses the .get method which handles the error for us (returning a None value)
#This second method is 'safer' because of how it handles this error
#compare to use using the two different methods for London
print(cities['London'])
print(cities.get('London'))
print(cities.get('London'))
Explanation: c) Check you understand the difference between the following two blocks of code by running them, checking the output and editing them (e.g. try the code again, but replacing Berlin with London)
End of explanation
for k, v in cities.items():
    print(k)
for k, v in cities.items():
    print("The city of " + str(k) + " has an airport code of " + str(v[2]) )
Explanation: d) Adapting the code below, print out the city name and airport code for every city in our Atlas.
End of explanation
for ??? in cities.???:
    print(??? + " is at latitude " + str(???))
for city, latitude in cities.items():
    print(city + " is at latitude " + str(latitude[0]))
Explanation: Loops
Recall from the previous notebook that loops are a way to iterate (or repeat) chunks of code. The two most common ways to iterate a set of commands are the while loop and the for loop. 
Working with Loops
The questions below use for loops. Replace ??? in the following code block to make the code work as instructed in the comments. If you need some hints and reminders, revisit the previous notebook.
a) Print out the name and latitude of every city in the cities dictionary using a for loop
End of explanation
for c in ???:
    print(???)
for c in cities.items():
    print(c)
Explanation: b) Print out every city on a separate line using a for loop:
End of explanation
citiesB = [
    {'name':     'San Francisco',
     'position': [37.77, -122.43],
     'airport':  'SFO'},
    {'name':     'London',
     'position': [51.51, -0.08],
     'airport':  'LDN'},
    {'name':     'Paris',
     'position': [48.86, 2.29],
     'airport':  'PAR'},
    {'name':     'Beijing',
     'position': [39.92, 116.40],
     'airport':  'BEI'}
]
for ??? in citiesB.???:
    print(??? + " is at latitude " + str(???))
citiesB = [
    {'name':     'San Francisco',
     'position': [37.77, -122.43],
     'airport':  'SFO'},
    {'name':     'London',
     'position': [51.51, -0.08],
     'airport':  'LDN'},
    {'name':     'Paris',
     'position': [48.86, 2.29],
     'airport':  'PAR'},
    {'name':     'Beijing',
     'position': [39.92, 116.40],
     'airport':  'BEI'}
]
for city in citiesB:
    print(city['name'] + " is at latitude " + str(city['position'][0]))
Explanation: c) Now print using a loop this new data structure:
End of explanation
<END_TASK>