I have a list:
ll=['the big grey fox','want to chase a squirell', 'because they are friends']
I want to split the 2nd element, ll[1]
, into "want to chase"
and " a squirell"
.
I want to end up with:
['the big grey fox','want to chase', ' a squirell', 'because they are friends']
Note that the first element needs to be always split so that the last 10 characters are a new element of the list, immediately after the first n-10 char of the element before, so that the order of joined text is not altered.
I currently use:
ll[:1],ll[1][:len(ll[1])-10], ll[1][-10:],ll[2:]
but is there a prettier way of doing this?
1
You can use:
ll[1:2] = ll[1][:-10], ll[1][-10:]
to replace a second element with split pair