mardi 10 avril 2018

Python - if statement - splitting string every x chars

so I have this data="6060526060". I'd like to split this string into every 4 chars. But if the number 52 appears, i'd like to spit this for 2 chars. i.e ['6060', '52', '6060'].

I currently have :

r = [data[i:i+4] for i in range(0, len(data),4)]

this puts it into every 4 chars, just having trouble getting the "52" into 2 serrate chars, thanks

Aucun commentaire:

Enregistrer un commentaire