Complete the code to get the value for key 'apple' from the dictionary.
fruits = {'apple': 5, 'banana': 3, 'orange': 2}
value = fruits[1]'apple'
print(value)Use square brackets [] to access a value by key in a dictionary.
Complete the code to find the index of value 7 in the list.
numbers = [3, 7, 1, 9] index = numbers.[1](7) print(index)
find which do not exist for lists.search or locate which are not list methods.The index() method returns the first index of the given value in a list.
Fix the error in the linked list traversal to print all node values.
class Node: def __init__(self, val): self.val = val self.next = None head = Node(1) head.next = Node(2) head.next.next = Node(3) current = head while current is not None: print(current[1]val) current = current.next
-> which is not valid in Python.Use dot . to access attributes of an object in Python.
Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
< instead of > for filtering.len(word) for the value.Use len(word) to get the length and > to filter words longer than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts for counts greater than 0.
data = {'apple': 2, 'banana': 0, 'cherry': 5}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)k.lower() instead of k.upper().== or < instead of >.Use k.upper() for uppercase keys, v for values, and filter with > 0.