1

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.
     ...

1 Answer 1

6
[tuple(x.split(',')) for x in a]
Sign up to request clarification or add additional context in comments.

3 Comments

tuple(x.split(',')) would be nicer I think. It uses one less split :)
Thanks. This works fine (btw., how can I mark a suggested solution here as solved or give stars of reward?)
@Krischu Click on the tick below the vote counts so that it turns green and stays green. thank you. You also have enough reputation to give an upvote (click on the arrow above the 4)- which is also greatly appreciated. If you could do both, that would be great. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.