[英]Assigning comma separated strings to an array of tuples - python, numpy
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']
['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
. 最终目标是将其与
version
和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.
...
[tuple(x.split(',')) for x in a]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.