Lists · practice
Measure, Search, and Slice Lists
You already know several operations that work with
Measure and check membership
len() counts list items. The in
The membership checks produce
Take a slice
A list
The slice contains Oslo, Kyoto, and Lima. Like a string slice, a list slice creates a new value.
What does this code print?
letters = ["a", "b", "c", "d"]
print("c" in letters)
print(letters[1:3])In the exercise, measure one list, check for one item, and take its middle slice. Length and slice boundaries transfer from strings. The new in operator adds a way to ask whether the list contains a value.
Task
Complete the program using the existing destinations
Store its item count in
count.Store whether
"Kyoto"is present inhas_kyoto.Store the
from 1up to but not including index4inmiddle.Print
count,has_kyoto, andmiddle, one per line.