A4 · Problem set 3
Problem set 3: lists, dictionaries and sets
These labs use lessons 12 and 13: lists, dictionaries and sets, with the loops and functions from before. Each one handles the kind of data a bench or a design produces: readings, parts lists and netlists. When a check fails, the hidden test's message says which case went wrong.
Check
Write peaks(x, threshold) returning the indices of the local maxima of a list: entries greater than both neighbors and above threshold (the first and last entries never count). Set p = peaks(x, th) for the starter's list and th = 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two boards' parts lists are dictionaries from part number to quantity. Write merge(a, b, boards_b=1) returning one dictionary with the total of each part, where b is needed boards_b times. Set m = merge(main, sensor, k) for 3 sensor boards.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write stats(x) that makes a single pass over a list and returns (lo, hi, rms), its minimum, maximum and RMS, without min, max or sum. Set s = stats(v) for the starter's n = 1000 readings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A test plan lists test points, and the bench log records which were measured (some more than once, and some by mistake that aren't in the plan). Using sets, set missed to the sorted list of planned points never measured, extra to the sorted list of measured points not in the plan, and coverage to the fraction of the plan measured, after logging m = 5 more points from the starter's more list.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An ADC's noisy readings sit around one value. Using a dictionary, count how often each code appears, then set mode to the most common code (the smallest one if there's a tie), spread to the largest code minus the smallest, and counts to the dictionary. The starter makes n = 1000 codes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A small sensor array's readings are a list of rows. Write transpose(m) returning its columns as rows, without NumPy, then set t = transpose(grid), col_sums to the sum of each column, and row_r to row 1 of the transpose.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each part is a tuple (name, ohms, tolerance_percent). Set ranked to the list of names sorted by tolerance, tightest first, and by value within the same tolerance, then top to the first k = 2 names.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.