20.8 - Traversing a List (Looping Through a List)
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
What will be the output of the following code? fruits = ['apple', 'banana', 'mango']; for fruit in fruits: print(fruit)
💡 Hint: Think about what each element in the list is.
How do you access the first element of the list using indexing?
💡 Hint: Remember, indexing starts from 0!
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What is the output of the code fruits = ['apple', 'banana', 'mango']; for i in range(len(fruits)): print(fruits[i])?
💡 Hint: Think of what the loop is doing with each index.
True or False: Using for fruit in fruits is the only way to traverse a list.
💡 Hint: Consider the different methods we've discussed.
Get performance evaluation
Challenge Problems
Push your limits with advanced challenges
Write a function that takes a list of numbers and returns a new list with each number doubled using traversal.
💡 Hint: Consider how the items should be processed as you traverse the list.
Given a 2D list, write a function that returns the sum of all the inner lists by traversing.
💡 Hint: You will need to traverse the outer list and then the inner lists.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.