나는 이렇게 학습한다/Algorithm & SQL

1227. CSV representation of array

daco2020 2022. 12. 27. 21:22

Create a function that returns the CSV representation of a two-dimensional numeric array.

Example:

input:
   [[ 0, 1, 2, 3, 4 ],
    [ 10,11,12,13,14 ],
    [ 20,21,22,23,24 ],
    [ 30,31,32,33,34 ]] 

output:
     '0,1,2,3,4\n'
    +'10,11,12,13,14\n'
    +'20,21,22,23,24\n'
    +'30,31,32,33,34'

Array's length > 2.



Solution:

def to_csv_text(array):
    return '\n'.join(','.join(map(str, i)) for i in array)