0
0
Pythonprogramming~10 mins

Searching and counting elements in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count how many times the number 5 appears in the list.

Python
numbers = [1, 5, 3, 5, 7, 5]
count_fives = numbers.[1](5)
print(count_fives)
Drag options to blanks, or click blank then click option'
Aindex
Bcount
Cfind
Dsearch
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'index' instead of 'count' which only finds the first position.
2fill in blank
medium

Complete the code to check if the word 'apple' is in the list of fruits.

Python
fruits = ['banana', 'orange', 'apple', 'grape']
if 'apple' [1] fruits:
    print('Found apple!')
Drag options to blanks, or click blank then click option'
Ain
Bhas
Cnot
Dis
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'is' which checks identity, not membership.
3fill in blank
hard

Fix the error in the code to find the index of the first occurrence of 7 in the list.

Python
values = [4, 7, 2, 7, 9]
position = values.[1](7)
print(position)
Drag options to blanks, or click blank then click option'
Alocate
Bfind
Csearch
Dindex
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'find' which is not a list method and causes an error.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 letters.

Python
word_lengths = {word: [1] for word in words if len(word) [2] 4}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '<=' instead of '>' which selects shorter words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their counts as values, but only for words that appear more than once.

Python
word_counts = { [1] : words.count([2]) for [3] in words if words.count([3]) > 1 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
Ditem
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different variable names inconsistently.