If I had a set of .csv values in a string:
What is a clever way to efficiently get them in an array?
['00.1', '00.2', '00.3', '00.4']
The simplest way would be:
csv_string = '00.1,00.2,00.3,00.4' csv_list = csv_string.split(',') # => ['00.1', '00.2', '00.3', '00.4']
or, if you need the result as a list of numbers:
csv_list = [float(x) for x in csv_string.split(',')] # => [0.1, 0.2, 0.3, 0.4]
This is a somewhat naive approach though, there are various "dialects" of csv, and if you're dealing with real data that you get from elsewhere, you'll probably want to look at the
csvmodule (part of the standard library).
Wow, brilliant. Now you guys are just showing off.....Thank you!
Sometimes I think their just making things up 😂😂