A4 · Problem set 4
Problem set 4: collections
These labs use lessons 12 to 16: lists, dictionaries and sets, iteration patterns, and errors and testing. They're the everyday chores of analyzing measurements and handling parts lists.
Check
Each string in the starter's list is like "R1=4.7k". Using the parse function given, set bom to a dictionary from each name to its value in base units.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set m and s to the mean and sample standard deviation of x, then outliers to the readings more than 2 standard deviations from the mean, in their original order.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Count how many parts connect to each node. Set degree to a dictionary from node name to that count.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the sweep in the starter, set gain_db to the list of gains in dB (), and f3 to the first frequency whose gain is more than 3 dB below the first one's.
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). Set ranked to the list of names sorted by the power each dissipates at V = 5 V, largest first.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set avg to the moving average of x over a window of w = 4: entry i is the mean of x[i:i+w], for every full window.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Some strings in the starter's list aren't numbers. Set total to the sum of the ones that are, and bad to how many weren't, using try and except ValueError.
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.