Complete the code to create a simple line plot using matplotlib.
import matplotlib.pyplot as plt data = [1, 3, 2, 5, 7] plt.[1](data) plt.show()
The plot function draws a line plot connecting the data points.
Complete the code to add labels to the x-axis and y-axis of the line plot.
import matplotlib.pyplot as plt data = [2, 4, 6, 8] plt.plot(data) plt.xlabel([1]) plt.ylabel('Value') plt.show()
The xlabel function sets the label for the x-axis. It needs a string like 'Time'.
Fix the error in the code to correctly plot two lines on the same graph.
import matplotlib.pyplot as plt x = [1, 2, 3] y1 = [2, 4, 6] y2 = [1, 3, 5] plt.plot(x, y1) plt.plot(x, [1]) plt.show()
To plot the second line, use the second y-values list y2 with the same x-values.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.
words = ['data', 'science', 'is', 'fun'] lengths = { [1]: [2] for word in words if [3] }
The dictionary comprehension uses word.upper() as keys, maps to len(word), and filters words with length greater than 3.