Respuesta :
Answer:
The solution code is written in Python 3.
- def processCSV(CSV_string, index):
- data = CSV_string.split(",")
- result = data[index]
- return int(result)
- processCSV('111,22,3333,4', 2)
Explanation:
Firstly, create function and name it as processCSV() with two parameters, CSV_string and index (Line 1).
Since the CSV_string is a collection of integers separated by comma, we can make use of Python String built-in method split() to convert the CSV_string into a list of numbers by using "," as separator (Line 2).
Next, we can use the index to extract the target value from the list (Line 3).
Since the value in the list is still a string and therefore we shall use Python built-in method int() to convert the target value from string type to integer and return it as output of the function (Line 4)
We can test our function by using the sample test case (Line 6) and we shall see the expected output: 3333.
The program which returns the nth term of a comma seperated value written in python 3 is given below :
def ret_ind(csv_string, index):
#initialize a function called ret_ind which takes in two parmaters ; a csv data and an integer index
csv_data = csv_string.split(',')
#since each Value is seperated by a comma, we can split using the string split method to make each value distinct.
nth_index = csv_data[index]
#using list slicing, we subset the required value using the passed in index parameter
return int(nth_index)
#return the nth index and convert to an integer
# A sample run of the program and the output is attached below.
print(ret_ind('111,22,3333,4', 3))
Learn more :https://brainly.com/question/14276852
