

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Lists
incomplete
2: Lists Continued
incomplete
3: Counting in Programming
incomplete
4: Indexing Into Lists
incomplete
5: List Length
incomplete
6: List Updates
incomplete
7: Appending in Python
incomplete
8: Pop Values
incomplete
9: Counting the Items in a List
incomplete
10: No-Index Syntax
incomplete
11: Find an Item in a List
incomplete
12: Find the Increase
incomplete
13: Find Max
incomplete
14: Modulo Operator in Python
incomplete
15: Slicing Lists
incomplete
16: List Operations – Concatenate
incomplete
17: List Operations – Contains
incomplete
18: List Deletion
incomplete
19: Tuples
incomplete
20: First Element
incomplete
21: Reverse List
incomplete
22: Filter Messages
incomplete
23: Even Teams
incomplete
24: Alchemy Ingredients
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Some of our players would like to view their inventories in reverse order.
Using a loop, let's write a function that takes a list as an input and returns a new list except all the items are in reverse order.
For example:
[1, 2, 3] -> [3, 2, 1]
['a', 'b', 'c', 'd'] -> ['d', 'c', 'b', 'a']The Python range function is very useful when working with lists. It allows you to choose where to start, stop, and how to step over a list.
Remember, function arguments are separated by commas inside the parentheses. For range the function signature is range(start, stop, step). Don't forget you can use negative values for these arguments!
It's common to nest built-ins: you can pass len(...) directly to range(...). For example, range(len(items)) iterates over indices 0 through len(items) - 1.
Where should you start your loop from? Could len() be useful at giving range a starting index?
Where should you end your loop?
What should the step be? In other words, how should you increment i in each iteration of the loop?