user12297342
user12297342

Reputation: 23

Convert a list of delimited strings to a list of lists

I am importing arrays from a CSV file.

Example:

arr = ['foo1;foo2;foo3', 'baa1;baa2;baa3', 'bla1;bla2;bla3'] 

I now want to transform these semicolon seperated strings to a list of lists:

arr2 = [['foo1', 'foo2', 'foo3'], ['baa1', 'baa2', 'baa3'], ['bla1', 'bla2', 'bla3']]

How can I do this? I am struggling to find the right combination of split, append and delimiters to do this.

Upvotes: 0

Views: 218

Answers (1)

AlexisBRENON
AlexisBRENON

Reputation: 3079

Use list comprehension:

arr2 = [s.split(';') for s in arr]

Upvotes: 3

Related Questions