[tuple(x.split(',')) for x in a]
Assigning comma separated strings to an array of tuples - python, numpy
Question
Some shell escape command gives me:
a=!ls /cygdrive/s | grep "^Something6" | tr -d [A-Za-z] | sed "s/_.*$//" | sed "s/-/ /" | sed "s/ /,/"
['64,2014-04-01', '64,2014-04-02', '64,2014-04-03', '64,2014-04-04', '64,2014-04-07', '64,2014-04-07', '64,2014-04-08', '64,2014-04-09', '64,2014-04-11', '64,2014-04-14']
The final goal is to put this into a database with the columns version
and date
.
For intermediate experimenting I would like to put the array of strings
into an array of tuples or into a dictionary without much copying around.
Like:
version = np.empty(1,dtype=object_)
date = np.empty(1,dtype=object_)
version = a[1:]
But I need to split the string at the ','. How can this be achieved most elegantly with one gulp?
The result should be something like:
(('64','2014-04-01'),
('64','2014-04-02'),
etc.
...
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow