

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
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
Python makes it easy to slice and dice lists to work only with the section you care about. One way to do this is to use the simple slicing operator, which is just a colon :.
With this operator, you can specify where to start and end the slice, and how to step through the original list. List slicing returns a new list from the existing list.
The syntax is as follows:
my_list[start:stop:step]
For example:
scores = [50, 70, 30, 20, 90, 10, 50]
# Display list
print(scores[1:5:2])
# Prints [70, 20]
The above uses a start of 1, a stop of 5 (not included), and a step of 2. All of the sections are optional.
You can also omit various sections ("start," "stop," or "step"). For example, numbers[:3] means "get all items from the start up to (but not including) index 3." numbers[3:] means "get all items from index 3 to the end."
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[:3] # Gives [0, 1, 2]
numbers[3:] # Gives [3, 4, 5, 6, 7, 8, 9]
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[::2] # Gives [0, 2, 4, 6, 8]
Negative indices count from the end of the list. For example, numbers[-1] gives the last item in the list, numbers[-2] gives the second last item, and so on.
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[-3:] # Gives [7, 8, 9]
Interactive example available with JavaScript enabled.
Complete the given get_champion_slices function. It takes a list of champions and should return three new lists based on the given champions:
return value1, value2, value3