Kelvin Davis Kelvin Davis - 19 days ago 5
Python Question

String slicing, iterations and list quesiton

Say I have the string "BigJon".

Is there way to iterate through and slice it into two different words like

B igJon
,
Bi gJon
,
Big Jo
n,
Bigj on
and so on. And then all these separate pieces be a list?

Answer

One liner list comprehension

['%s %s' % (a[:i], a[i:]) for i in range(1, len(a))]

Comments