Lists

Indices and tables

Background

Like tuples, lists are similar to arrays and can hold any object type. Recall thought that unlike tuples, lists are mutable and can be changed after creation without creating a new object. As a result of this mutability, even though lists and tuples are both sequences and share many operations, there are additional operations available to the list class that aren’t available to the tuple class.

Exercise

Sensor data from sensors mounted to several DUTs was collected and is listed in Table 7. As is common with real-world data, the measurements are not necessarily continuous. Use this data to complete the following exercises.

Table 7 Table of Data for List Exercises
DUT Name Sensor-A Samples Sensor-B Samples
CHZ 192, 4, 1, 54 228, 147, 61, 84
RXJ 33 48, 41, 910
AMP 292, 12, 84, 991 28901
  1. Create individual lists to hold the samples from each sensor in each DUT.
  2. You noticed that you forgot to include some samples for sensor-A of RXJ. Extend the sample list for that sensor with the following samples: 55, 21
  3. AMP sensor-a, sample 2 is incorrect. Instead of being 84, it should have been 94. Correct the sample list for that sensor.
  4. CHZ sensor-b, samples 2 and 3 are incorrect, they should be, 71 and 94 respectively. Correct the sample list for that sensor.
  5. Join all sample values together into a single sample set list.
  6. Find the count of, min, max and sum of the values in the sample set.
  7. Determine if the value 71 occurs in the sample set.
  8. Confirm the value 60 is not in the sample set.
  9. Determine how many times the value of 228 occurs in the sample set.
  10. Get the first sample from the sample set
  11. Get the last sample from the sample set
  12. Get every 4th sample from the sample set.
  13. Sort the sample set from smallest to largest.
  14. Sort the sample set from largest to smallest.
  15. Create a list-of-tuples to represent the original table of data (including all it’s subsequent data modifications).
  16. Insert a new row onto the end of the table of data with the following criteria:
DUT Name: “BMX”
Sensor-A Samples: 1, 4, 6, 735
Sensor-B samples: 12, 135, 2462
  1. Insert a new row into the table of data, after the “CHZ” row, with the following critera:
DUT Name: “QRT”
Sensor-A Samples: 2, 31, 52, 85
Sensor-B samples: 899, 900, 901
  1. You decided that the AMP data is no good. Remove it from the table.
  2. Sort the sample table rows (records) alphabetically by DUT name.
  3. Return a count of the number of records in the table.

Hints

  • You may want to refresh your memory on how to make a lambda function.

Solution

When you are ready to see one possible solution, download and open this Jupyter Notebook file