1
00:00:05,260 --> 00:00:09,960
Alright, so let's talk about processing
nested lists. So we've got a list here

2
00:00:09,960 --> 00:00:15,280
called menu, containing eight lists. Each
of those lists contain items that make

3
00:00:15,280 --> 00:00:19,099
up the meals on the menu. In case you're
wondering why there's so much spam in

4
00:00:19,099 --> 00:00:23,390
these meals, the menu's based on a Monty
Python sketch. The Python programming

5
00:00:23,390 --> 00:00:27,060
language got its name, incidentally, from
Monty Python. Search the internet

6
00:00:27,060 --> 00:00:31,420
for Monty Python's Spam sketch and you can watch it
on YouTube when you feel like a break. That sketch,

7
00:00:31,429 --> 00:00:36,110
by the way, is also the reason we now
refer to junk emails as spam. Alright,

8
00:00:36,110 --> 00:00:39,500
so what we're going to do is run through
each of the meals, and try and find one

9
00:00:39,500 --> 00:00:46,160
that doesn't contain spam. So starting on
line 12, I'm going to type for meal

10
00:00:46,160 --> 00:00:55,120
in menu colon. Then I'm going to type if space
double quotes,  with spam in those double quotes,

11
00:00:55,120 --> 00:01:04,069
not in meal colon, print meal, in
parentheses. So it should print only the

12
00:01:04,069 --> 00:01:08,540
lists that don't contain spam. On the
screen there, you can see that's egg and

13
00:01:08,540 --> 00:01:15,490
bacon, and also egg, sausage and bacon.
Let's run the program to confirm that

14
00:01:16,060 --> 00:01:20,880
You can see that's the right output. Now
each of the items on the menu are

15
00:01:20,880 --> 00:01:25,940
themselves lists. Once you find one
without spam, you can print its items.

16
00:01:25,940 --> 00:01:30,600
Let's go ahead and do that, down
here, on line 16, and I'm going to come over here

17
00:01:30,600 --> 00:01:40,120
and I'm going to add for space item in
meal colon print and then item in parentheses.

18
00:01:40,120 --> 00:01:44,920
You'll often see nested loops used like this,
to process nested lists.

19
00:01:44,920 --> 00:01:48,800
Now we can also use the count
method, that sequence types have, to count

20
00:01:48,800 --> 00:01:53,500
how much spam is in each meal. So let's have
a go doing that, and to do that we need

21
00:01:53,509 --> 00:02:01,090
to add an else block, on line 18 over here;
else colon, then on line 19, print

22
00:02:01,090 --> 00:02:07,320
parentheses double quotes. We want zero
in left and right curly braces,

23
00:02:07,320 --> 00:02:16,880
has a spam score of, then 1 in left and right curly
braces. Press ENTER there,

24
00:02:16,880 --> 00:02:23,620
and type dot format on the next line,
parentheses meal comma meal.count

25
00:02:23,620 --> 00:02:28,380
parentheses double quotes, with the word
spam in those double quotes. We've got

26
00:02:28,380 --> 00:02:40,620
three right closing parentheses. Alright, so let's
run the program to see how much spam each meal contains.

27
00:02:40,620 --> 00:02:44,020
So just in case it wasn't obvious, you can use any

28
00:02:44,020 --> 00:02:48,800
expression in dot format. So on line 20,
we call the count method of the meal

29
00:02:48,810 --> 00:02:53,040
sequence, and it's the value that returns
that gets printed. That also shows how to

30
00:02:53,040 --> 00:02:56,670
use the count method, which means we've
now covered everything in that table of

31
00:02:56,670 --> 00:03:01,580
sequence operations. So let's briefly go back to that again,

32
00:03:05,980 --> 00:03:12,480
this one here. Alright, so time now for a
challenge. Let's go back to IntelliJ.

33
00:03:12,480 --> 00:03:23,480
We need a new file here. Let me take a copy of
these items - lines 1 to 10, inclusive.

34
00:03:23,480 --> 00:03:32,000
Then we need a new file.
I'm gonna call this one nospam.

35
00:03:32,000 --> 00:03:35,760
I'm gonna paste that code back in there.

36
00:03:36,219 --> 00:03:39,209
Alright, so let's talk about the
challenge.

37
00:04:36,860 --> 00:04:41,940
So we will go over a couple of
solutions to this, in the next video.

