Tuples¶
Indices and tables¶
Background¶
Tuples are similar to arrays but can hold any object type. They are a great way to hold and manipulate immutable data in Python.
Exercise¶
Sensor data from sensors mounted to several DUTs was collected and is listed in Table 6. As is common with real-world data, the measurements are not necessarily continuous. Use this data to complete the following 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 |
- Create individual tuples to hold the samples from each sensor in each DUT.
- Join all sample values together into a single sample set tuple.
- Find the count of, min, max and sum of the values in the sample set.
- Determine if the value 41 occurs in the sample set.
- Confirm the value 22 is not in the sample set.
- Determine how many times the value of 84 occurs in the sample set.
- Get the first sample from the sample set
- Get the last sample from the sample set
- Get every 4th sample from the sample set.
- Sort the sample set from smallest to largest.
- Sort the sample set from largest to smallest.
- Create a tuple-of-tuples to represent the original table of data.
- Sort the sample table rows (records) alphabetically by DUT name.
- Return a count of the number of records in the table.
Hints¶
- Tuples are immutable so they can’t use the mutable sequence operations.
- You may want to refresh your memory on how to make a lambda function.