Answer:
The solution code is written in Python 3.
- def convertCSV(number_list):
- str_list = []
- for num in number_list:
- str_list.append(str(num))
-
- return ",".join(str_list)
- result = convertCSV([22,33,44])
- print(result)
Step-by-step explanation:
Firstly, create a function, convertCSV(), that take one input which is a list of number, number_list. (Line 1)
Next, declare a new string list, str_list. (Line 2)
Use a for-loop to traverse the individual number in the number_list (Line 4) and add each of the number into the str_list. Please note, the individual number is converted to string type using Python str() method. (Line 5)
By now, the str_list should have a list of string type number. We can use join() method to join all the string element in the str_list into a single string and return it as an output. (Line 7) The "," acts as a separator between the element in the str_list.
We can test the function by passing a random list of number, (e.g. [22,33,44]) and the output shall be '22,33,44'. (Line 9 - 10)