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

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -