1
00:00:04,630 --> 00:00:09,070
So the challenge was to process the
values list that our code produced, and you

2
00:00:09,070 --> 00:00:13,480
can see that on screen. We need to
replace each of the string values with a

3
00:00:13,480 --> 00:00:19,440
numeric equivalent, and just to recap, if I
run this, there's the output down the bottom.

4
00:00:19,440 --> 00:00:23,540
So we've seen how to convert a
string to an int, using the int function.

5
00:00:23,540 --> 00:00:28,780
The solution involves iterating over the
list, and converting each value. There are

6
00:00:28,780 --> 00:00:32,360
a couple of ways you could do that, so
I'm going to write the code for both of them.

7
00:00:32,360 --> 00:00:34,539
The first method we're going to look at, is to

8
00:00:34,539 --> 00:00:38,800
replace each value, in turn, with its
integer equivalent. Let's have a go at

9
00:00:38,800 --> 00:00:45,200
doing that. I'm gonna start on line 29, with a
comment - this is the first option -

10
00:00:45,200 --> 00:00:53,320
to replace the value, or the values, in
place. The actual code will be for index

11
00:00:53,320 --> 00:00:59,220
in range, left parenthesis len left
parenthesis values_list,

12
00:00:59,220 --> 00:01:04,519
two right parentheses and a colon.
Then values_list left square bracket,

13
00:01:04,519 --> 00:01:11,460
index right square bracket, is equal to
int left parenthesis value_list,

14
00:01:11,460 --> 00:01:14,860
then our left square bracket again, index,

15
00:01:14,860 --> 00:01:25,200
right square bracket and right parenthesis.
Then line 33, we'll print out values_list.

16
00:01:25,200 --> 00:01:29,620
So we're iterating over the range of
indexes, from 0 to the length of the list.

17
00:01:29,620 --> 00:01:34,200
Remember that range doesn't include the
final value. Our indexes will run from 0

18
00:01:34,210 --> 00:01:39,609
to 6, because the length of the list is 7.
For each index value, we'll replace the

19
00:01:39,609 --> 00:01:45,189
item at that position with its integer
value. So we run the program now - you

20
00:01:45,189 --> 00:01:49,119
should hopefully see the list will
contain 7 ints, and we can see that's the

21
00:01:49,119 --> 00:01:52,179
case, there. Clearly we can see the
previous list there, which was strings,

22
00:01:52,180 --> 00:01:57,800
and then the latest list there, down the
bottom, which is a list of ints.

23
00:01:57,800 --> 00:02:03,399
I want to draw your attention to this warning on
line 31. You can see there, I've got a

24
00:02:03,399 --> 00:02:07,689
warning about unexpected types, if I
hover over it. Normally, you should pay

25
00:02:07,689 --> 00:02:11,650
attention to any warnings that your IDE
will give you. Here, what we're doing is,

26
00:02:11,650 --> 00:02:16,960
we're accessing string items in the list,
then assigning a new integer value.

27
00:02:16,960 --> 00:02:20,200
The checker's correctly
determined that we're assigning an int to

28
00:02:20,200 --> 00:02:25,000
something that was a string. It's warning
us, in case that's not what we intended.

29
00:02:25,000 --> 00:02:28,360
However, in this case, that's exactly what
we intended.

30
00:02:28,360 --> 00:02:32,760
We're mutating the entire list - replacing
all the strings with ints - so in this

31
00:02:32,770 --> 00:02:37,960
particular case, we can safely ignore
that warning. But strangely, though, it's

32
00:02:37,960 --> 00:02:42,490
the word index that's been highlighted,
and that can be confusing. That's not

33
00:02:42,490 --> 00:02:46,540
what it's complaining about, and we
can see that, if I replace int, over here,

34
00:02:46,540 --> 00:02:53,000
with string. The other warning's gone,
which shows that it was the integer value,

35
00:02:53,000 --> 00:02:56,460
on the right of the equals, that the checker objected to.

36
00:02:56,460 --> 00:03:00,310
Fortunately, strange results like this
are very rare, but I just thought I'd

37
00:03:00,310 --> 00:03:04,940
warn you about it, so you don't spend
hours trying to fix code that isn't broken.

38
00:03:04,940 --> 00:03:09,400
Most of the time - and I really do
mean most of the time - the warnings

39
00:03:09,400 --> 00:03:13,120
will be accurate, so keep that in mind. Alright,
so I'm going to undo that change and go

40
00:03:13,120 --> 00:03:17,500
back to our int. Run it again.
We should have the same output. Right, so

41
00:03:17,500 --> 00:03:22,450
let's move on. Now the other thing you
may have done, is instead, create a new

42
00:03:22,450 --> 00:03:30,060
list and append the integer values to it.
So I'm going to go ahead and do that.

43
00:03:30,060 --> 00:03:34,239
We'll make a comment that this is the second
method - this is creating a new list,

44
00:03:34,239 --> 00:03:38,560
or create a new list, will be our approach.
So I'll start by calling the new list

45
00:03:38,560 --> 00:03:43,959
integer values, so integer_values equals an empty list,

46
00:03:43,960 --> 00:03:49,380
which is left and right square brackets.
I'll use a for loop again, so for value

47
00:03:49,380 --> 00:03:56,540
in values_list  : and then integer_values

48
00:03:56,540 --> 00:04:04,269
dot append left parenthesis, int, left
parenthesis value, then two right closing

49
00:04:04,269 --> 00:04:12,000
parentheses. Then we'll print out the
output on line 40, print integer_values.

50
00:04:12,000 --> 00:04:14,940
So this time, we're getting each item from the list.

51
00:04:14,950 --> 00:04:20,709
We're converting it to an int and appending it
to the new list. So once again, run the

52
00:04:20,709 --> 00:04:25,240
program, and confirm that the new list
contains only ints, and you can see on

53
00:04:25,240 --> 00:04:29,710
screen there, that that is the case. There
are often several ways to do things,

54
00:04:29,710 --> 00:04:32,050
and you'll find that different ways will
have different

55
00:04:32,050 --> 00:04:38,520
advantage's and disadvantages. So can you
spot any advantages and disadvantages,

56
00:04:38,520 --> 00:04:43,270
with the two solutions on the screen
there, now. If you're not sure, watch the

57
00:04:43,270 --> 00:04:47,889
earlier videos, on removing items from a
list, again. Don't just think about the

58
00:04:47,889 --> 00:04:52,659
data we've got here - remember  to consider
when the list is very large. So I'd like

59
00:04:52,660 --> 00:04:58,100
you to think of one advantage, that the
first for loop has over the second,

60
00:04:58,100 --> 00:05:03,789
and also one disadvantage. Now please don't ask for the answer in the Q&A. At some point

61
00:05:03,789 --> 00:05:07,479
in the course, when it's a relevant part
of what we're discussing, I'll come back

62
00:05:07,479 --> 00:05:12,490
to this. Keeping you in suspense like
this may seem mean, OK I guess it really

63
00:05:12,490 --> 00:05:18,129
is mean, but programming's not just about
writing code. Often it's about asking the

64
00:05:18,129 --> 00:05:22,240
right questions. Having questions like
this in the back of your mind,

65
00:05:22,240 --> 00:05:27,219
will really help you to choose the optimal
way to write your code.  Alright, so

66
00:05:27,219 --> 00:05:31,000
that's the end of lists, for now.
We'll be using lists a lot, throughout the

67
00:05:31,000 --> 00:05:35,050
course. You'll see different ways that
they can be useful and get plenty of

68
00:05:35,050 --> 00:05:38,889
practice using them. But moving on in the
next video, we're going to look at

69
00:05:38,889 --> 00:05:44,250
another data type - tuples. See you in the
next video.

