python - Joining two list whereby the last element of list "A" and first element of list "B" are concatenated -
i have 2 lists concatenating using lista.extend(listb).
what need achieve when extend lista concatenate last element of lista first element of listb
an example of lists below
end of lista = ... '1633437.0413', '5417978.6108', '1633433.2865', '54']
start of listb = ['79770.3904', '1633434.364', '5417983.127', '1633435.2672', ...
obviously when extend below (note 54)
'5417978.6108', '1633433.2865', '54', '79770.3904', '1633434.364', '5417983.127 below want achieve last , first elements concatenated
[...5417978.6108', '1633433.2865', '*5479770.3904*', '1633434.364', '5417983.127...] any ideas?
you can achieve in 2 steps:
a[-1] += b[0] # update last element of tag on contents of b[0] a.extend(b[1:]) # extend b exclude first element example:
>>> = ['1633437.0413', '5417978.6108', '1633433.2865', '54'] >>> b = ['79770.3904', '1633434.364', '5417983.127', '1633435.2672'] >>> a[-1] += b[0] >>> a.extend(b[1:]) >>> ['1633437.0413', '5417978.6108', '1633433.2865', '5479770.3904', '1633434.364', '5417983.127', '1633435.2672']
Comments
Post a Comment