Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python split list on delimiter

Seems to be a simple question but I tried a dozen of possibilities without result.
I just want to change [‘55.00’, [‘CHF’, ‘0.00’]] into [[‘55.00’], [‘CHF’], [‘0.00’]]
or:

var1 = "55.00"
var2 = "CHF"
var3 = "0.00"

As an example, I tried:

mik = ['55.00', ['CHF', '0.00']]
mik = [s.split(',') for s in ','.join(mik).split(',')]

Result:[[‘C’], [‘H’], [‘F’], [‘ ‘], [‘0’], [‘.’], [‘0’], [‘0’]]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What could be the solution in my situation?

>Solution :

You can unpack your list. This answer assumes that you always have RHS of the format [el, [el2, el3]]

>>> var1, (var2, var3) = ['55.00', ['CHF', '0.00']]
>>> var1
'55.00'
>>> var2
'CHF'
>>> var3
'0.00'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading