Kelvin Davis Kelvin Davis - 1 year ago 92
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
Bigj on
and so on. And then all these separate pieces be a list?

Answer Source

One liner list comprehension

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download