Question
implement a function called unique_id(data) which takes in the data as a list of lists and returns a list of unique arbitration IDs. The IDs
implement a function called unique_id(data) which takes in the data as a list of lists and returns a list of unique arbitration IDs. The IDs are in the form of a string and are stored in a hexadecimal format. The returned list of IDs should be sorted in ascending order based on their string value. That is, you don't need to convert the type of the IDs into any other data type, as sorting by their default data type (string) is expected. Please note that, the order of columns in the provided CSV file may differ from file to file, so you should not assume that the column you are interested in will always be in the same position. You should use the header row (the first row in the CSV file) to identify the correct column based on its name, rather than its position in the file.
Note that ID values are stored in a string, but their values are in hex, and are always 3 digits long (even if not, you can sort by the string order). Hence, you won't have to convert the type into hex, sorting by its default data type (string) is expected and the returned list is expected to store ID values as strings.
this function may help you retrieve the data.
def get_data(filename):
# Open the file in read mode
with open(filename, 'r') as file:
# Read all lines from the file
lines = file.readlines()
# Initialize an empty list to store the data
data = []
# Iterate over the lines, splitting each line by comma and appending the result to the data list
for line in lines:
entry = line.strip().split(',')
data.append(entry)
# Return the resulting nested list
return data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started