1
00:00:01,200 --> 00:00:02,670
All right, it's time for yet another

2
00:00:02,670 --> 00:00:04,410
difficult coding exercise.

3
00:00:04,410 --> 00:00:06,090
So this is a difficult challenge.

4
00:00:06,090 --> 00:00:08,340
What you're going to do is you're going to pretend

5
00:00:08,340 --> 00:00:09,750
to be a pirate.

6
00:00:09,750 --> 00:00:10,890
What do I mean by that?

7
00:00:10,890 --> 00:00:13,800
We're going to use what we've learned about lists

8
00:00:13,800 --> 00:00:15,750
and especially nested lists

9
00:00:15,750 --> 00:00:18,120
in order to create a Treasure Map.

10
00:00:18,120 --> 00:00:22,560
So we've created a Treasure Map by creating three lists

11
00:00:22,560 --> 00:00:25,860
which I've called line1, line2, and line3,

12
00:00:25,860 --> 00:00:29,130
and I've combined them into a nested list

13
00:00:29,130 --> 00:00:31,200
by using the code line four,

14
00:00:31,200 --> 00:00:33,240
where I said, map equals

15
00:00:33,240 --> 00:00:36,150
another list that contains three lists.

16
00:00:36,150 --> 00:00:40,860
Your job is to take an input in a similar format

17
00:00:40,860 --> 00:00:43,440
to how you see maps are formatted,

18
00:00:43,440 --> 00:00:46,410
where we can take a letter and a number

19
00:00:46,410 --> 00:00:48,750
and then use those letters and numbers

20
00:00:48,750 --> 00:00:52,290
to access a particular location in our list

21
00:00:52,290 --> 00:00:57,000
and convert the entry into an X

22
00:00:57,000 --> 00:01:01,230
to mark a spot on our map where we've buried our treasure.

23
00:01:01,230 --> 00:01:04,170
Have a read through the instructions carefully,

24
00:01:04,170 --> 00:01:06,930
figure out how this is supposed to work,

25
00:01:06,930 --> 00:01:09,630
and then write your code in main.py

26
00:01:09,630 --> 00:01:13,290
between the two sections that I've already written for you.

27
00:01:13,290 --> 00:01:14,850
So we've got a print statement

28
00:01:14,850 --> 00:01:16,920
that prints out all three lines,

29
00:01:16,920 --> 00:01:18,930
and you shouldn't change any of the existing code

30
00:01:18,930 --> 00:01:21,450
in order to complete this challenge.

31
00:01:21,450 --> 00:01:22,410
It's a difficult one.

32
00:01:22,410 --> 00:01:23,550
Have a think about it.

33
00:01:23,550 --> 00:01:26,310
Think about the Example Inputs and Example Outputs

34
00:01:26,310 --> 00:01:28,773
in the instructions and give this a go.

35
00:01:39,601 --> 00:01:40,600
All right.

36
00:01:40,600 --> 00:01:41,460
I did warn you it's a difficult one,

37
00:01:41,460 --> 00:01:43,860
but there's no shame in checking the solution,

38
00:01:43,860 --> 00:01:46,500
especially if you've given it a good go.

39
00:01:46,500 --> 00:01:48,750
The first thing that our code does

40
00:01:48,750 --> 00:01:53,750
is to grab hold of the first letter that's in the input.

41
00:01:53,820 --> 00:01:57,780
In this case, it is B in the example input.

42
00:01:57,780 --> 00:02:00,180
And what we're going to do is we're going to use position

43
00:02:00,180 --> 00:02:02,100
which takes the entire input,

44
00:02:02,100 --> 00:02:05,640
get the letter at the first index,

45
00:02:05,640 --> 00:02:08,490
so, position[0]

46
00:02:08,490 --> 00:02:12,093
and now we have that first letter from the input.

47
00:02:13,050 --> 00:02:14,400
Now the next thing we're going to do

48
00:02:14,400 --> 00:02:17,940
is we're going to turn this letter into lowercase

49
00:02:17,940 --> 00:02:21,570
so that we can compare it against a comparable.

50
00:02:21,570 --> 00:02:23,790
I've used the .lower() on line eight

51
00:02:23,790 --> 00:02:27,030
in order to lowercase the input letter

52
00:02:27,030 --> 00:02:29,430
just in case a user used the capital.

53
00:02:29,430 --> 00:02:32,580
And then on line nine, I've created a list

54
00:02:32,580 --> 00:02:34,950
that represents the three possible letters.

55
00:02:34,950 --> 00:02:36,600
We've got a, b, and c.

56
00:02:36,600 --> 00:02:39,358
Now, you could do it the other way

57
00:02:39,358 --> 00:02:40,860
and make it go uppercase as well,

58
00:02:40,860 --> 00:02:42,720
but everything has to be uniform

59
00:02:42,720 --> 00:02:46,020
in order to make sure that the user input

60
00:02:46,020 --> 00:02:48,600
doesn't matter if they put in lowercase or uppercase,

61
00:02:48,600 --> 00:02:51,480
our code will still work and can compare it

62
00:02:51,480 --> 00:02:54,633
against the values in this list of a, b, c.

63
00:02:55,560 --> 00:02:57,750
In order to do the comparison,

64
00:02:57,750 --> 00:03:01,560
we're using a method that comes from the Python list

65
00:03:01,560 --> 00:03:03,300
called index.

66
00:03:03,300 --> 00:03:05,010
So the way that we do this

67
00:03:05,010 --> 00:03:08,610
is we take the name of the list, which is a, b, c,

68
00:03:08,610 --> 00:03:10,710
and then we write .index,

69
00:03:10,710 --> 00:03:13,170
and then in the parentheses of that method,

70
00:03:13,170 --> 00:03:15,630
we pass in whatever it is we want to check

71
00:03:15,630 --> 00:03:17,760
that exists in the list.

72
00:03:17,760 --> 00:03:22,760
If the letter was b, as in this case in our input,

73
00:03:22,950 --> 00:03:27,630
then abc.index(b) is going to give us a number,

74
00:03:27,630 --> 00:03:29,280
it's going to give us 1,

75
00:03:29,280 --> 00:03:31,320
because remember lists start from 0.

76
00:03:31,320 --> 00:03:34,320
So a is at index 0, b is at 1, c is at 2.

77
00:03:34,320 --> 00:03:37,980
So now letter_index is 1,

78
00:03:37,980 --> 00:03:41,670
and we can work with it in order to get hold of the item

79
00:03:41,670 --> 00:03:44,400
in our map that we want to change.

80
00:03:44,400 --> 00:03:47,730
This part is a little bit difficult to conceptualize,

81
00:03:47,730 --> 00:03:50,460
but you can try thinking about this code,

82
00:03:50,460 --> 00:03:52,290
printing out what the values are

83
00:03:52,290 --> 00:03:54,450
and making sure you understand.

84
00:03:54,450 --> 00:03:57,690
The next part is getting hold of the number_index

85
00:03:57,690 --> 00:03:58,740
which is a lot easier

86
00:03:58,740 --> 00:04:01,260
because we can simply take the input

87
00:04:01,260 --> 00:04:03,960
which comes in through the variable position,

88
00:04:03,960 --> 00:04:05,670
get the value at index 1

89
00:04:05,670 --> 00:04:10,590
which is the second digit or letter in the input,

90
00:04:10,590 --> 00:04:12,990
and in this case, it's the number 3.

91
00:04:12,990 --> 00:04:14,460
And in our map

92
00:04:14,460 --> 00:04:18,660
because we have a list and remember lists start from 0,

93
00:04:18,660 --> 00:04:22,770
s o actually position 3 is equivalent to index 2.

94
00:04:22,770 --> 00:04:27,210
So we always have to subtract 1 in order to get the index

95
00:04:27,210 --> 00:04:30,270
because it starts counting from 0.

96
00:04:30,270 --> 00:04:32,613
So now we have the number_index.

97
00:04:33,570 --> 00:04:37,770
Finally, we can bring up our nested list, our map,

98
00:04:37,770 --> 00:04:40,740
and put in both of these indices

99
00:04:40,740 --> 00:04:44,550
in order to change the item at that position

100
00:04:44,550 --> 00:04:46,410
to the letter X.

101
00:04:46,410 --> 00:04:49,170
The thing that might be a little bit confusing here

102
00:04:49,170 --> 00:04:53,610
is the first part is actually the number_index

103
00:04:53,610 --> 00:04:57,150
because remember we said that with nested lists

104
00:04:57,150 --> 00:05:00,090
we go from outside to in.

105
00:05:00,090 --> 00:05:03,660
And what that means is we've got a list of lists.

106
00:05:03,660 --> 00:05:08,660
So if you look at line four, our outer list is our map

107
00:05:09,270 --> 00:05:11,910
with line1, line2, line3,

108
00:05:11,910 --> 00:05:15,510
and the part of our input that determines

109
00:05:15,510 --> 00:05:18,060
which of those lines we're going to pick out

110
00:05:18,060 --> 00:05:20,670
is actually the number, not the letter.

111
00:05:20,670 --> 00:05:23,400
So that's why the first index that goes in

112
00:05:23,400 --> 00:05:24,990
is the number_index.

113
00:05:24,990 --> 00:05:27,540
And then once we've gotten onto the correct

114
00:05:27,540 --> 00:05:29,730
line1, line2, or line3,

115
00:05:29,730 --> 00:05:31,290
then we use the letter_index

116
00:05:31,290 --> 00:05:33,210
in order to pick out the right element

117
00:05:33,210 --> 00:05:36,840
in that nested inner list.

118
00:05:36,840 --> 00:05:38,940
This again, is a little bit mind blowing.

119
00:05:38,940 --> 00:05:41,310
It's difficult to get your head around,

120
00:05:41,310 --> 00:05:44,070
but it's okay if you just try it a few times,

121
00:05:44,070 --> 00:05:47,040
try the code, try some different combinations

122
00:05:47,040 --> 00:05:49,200
and eventually you will get around

123
00:05:49,200 --> 00:05:51,300
to this programmer's way of thinking

124
00:05:51,300 --> 00:05:52,890
which is a little bit different

125
00:05:52,890 --> 00:05:54,660
to what you might be used to.

126
00:05:54,660 --> 00:05:56,010
Be patient with yourself.

127
00:05:56,010 --> 00:05:57,600
If you have any changes you need to make,

128
00:05:57,600 --> 00:05:59,900
go back to the previous slide and make it now.

