Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Long Breakfast (Exercise)
00:00
Now that you’ve worked on such a yummy shopping list, I think it’s time for a long breakfast. Start by creating a list called breakfast from the string, “eggs, fruit, orange juice.”
00:11
But there’s a space in between, which I guess is notable because you should create the list using the .split() method. Okay? So you’ve got to think about what is the separating character or characters that you can identify in the string so that you can use .split() on the string to get a list that has these three elements in it.
00:33
And then the second task is to verify that the breakfast list actually has three items in it. And you can do that using the len() function.
00:41
And then finally, you should create a new list called lengths using a list comprehension that contains the length of each string in the breakfast list.
00:50
Okay, so you get to practice how to create a list from a string using the .split() method. Then also just check that you did it the right way, and then also write a list comprehension.
01:02 Sounds yummy too. All right, take your time. It’s a long breakfast. And then see you in the next lesson where you’ll see me solve it.
Become a Member to join the conversation.