Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Review Python Lists So Far (Exercises)

00:00 Here are a couple of review exercises that you can work on to train the skills that you’ve heard about in the past lessons. Start by creating a list named food with two elements, "rice" and "beans", both of them strings.

00:14 Then you want to append the string "broccoli" to food using the .append() method. Then also add the strings "bread", and "pizza" to the food list, but this time using .extend().

00:25 And then you should print the first two items in the food list using print() and slice notation. And then also print the last item in food using print() and index notation.

00:35 So this is just to get you to train a little bit the concepts that you’ve learned, and I’ve got some more for you.

00:42 Next, you can create a list called breakfast, but create it from the string "eggs, fruit, orange juice". So you have one string, "eggs, fruit, orange juice".

00:53 And then use the .split() method to create a list from those. That should only contain three items. Second, you should verify that the breakfast list has only three items.

01:05 And then finally, also create a new list called lengths. Here you should use a list comprehension to calculate the lengths of each of the strings in the breakfast list and then put them into the new lengths list.

01:18 So remember, in the list comprehension, you can do this in one line. So this is a nice way to train using this very Pythonic way of doing calculations on elements in a collection.

01:30 Okay, go train these concepts a bit. Putting in some coding time always helps to fortify your memory and figure out if you understood everything that you’ve heard about.

Become a Member to join the conversation.