python 3.6 changing a list to a 2 digit then a space -


i have saw , works on shell need way work on python editor can help

a = '345674655' [a[i:i+3] in range(0, len(a), 3)] 

and outputs

['345', '674', '655'] 

this want can not on shell on print

how work know how works can't too?

a = '345674655' ar = [a[i:i+3] in range(0, len(a), 3)] print(*ar)  str2= " | ".join(ar(e) e in ar) print (str2) 

is want?

a = '345674655' ar = [a[i:i+3] in range(0, len(a), 3)] print(*ar) 

output:

345 674 655 

updated: second update: no need use list comprehension in case @darthfett's comment.

a = '345674655' ar = [a[i:i+3] in range(0, len(a), 3)] print(*ar)  str2= " | ".join(ar) print (str2) 

updated output:

345 674 655 345 | 674 | 655 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -