Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split value of string within array of arrays in Python

Tags:

python

arrays

I've an arrays of arrays called arr and I want to split the second value of each array. This means, if I've 0-6 I would like to modify it to '0','6'

What I have:

arr = [['PROVEEDOR', '0-6', '11111'], ['tiempo ida pulidor', '6-14', '33333']]

What I would like to have:

arr = [['PROVEEDOR', '0', '6', '11111'], ['tiempo ida pulidor', '6', '14', '33333']]

How can I do this conversion? It's always the second value, and always have two numbers. I know I've to use .split('-') but I know dont know to make it work here to make the replacement, as I've to iterate between all the arrays included in arr.

Thanks in advance.

like image 946
Avión Avatar asked Dec 02 '22 20:12

Avión


1 Answers

If you want to do it inplace:

In [83]: arr = [['PROVEEDOR', '0-6', '11111'], ['tiempo ida pulidor', '6-14', '33333']]

In [84]: for i in arr:
    ...:     i[1:2]=i[1].split('-')

In [85]: arr
Out[85]: [['PROVEEDOR', '0', '6', '11111'], ['tiempo ida pulidor', '6', '14', '33333']]
like image 169
zhangxaochen Avatar answered Dec 05 '22 11:12

zhangxaochen