Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3303990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:00:52+00:00 2026-05-17T21:00:52+00:00

I have two lists of strings that, in a better world, would be one

  • 0

I have two lists of strings that, in a better world, would be one list. I need to concatenate the lists, but the last element of the first list needs to be concatenated with the first element of the second list. So these guys:

list1 = ["bob", "sal"]
list2 = ["ly", "nigel"]

needs to become

out = ["bob", "sally", "nigel"]

So this isn’t hard, but I’m wondering why my one liner doesn’t work?

out = (list1[-1] += list2.pop(0)) += list2

Why isn’t this equivalent to

out =  list1[-1]+=list2.pop(0)
out += list2

?

I have to do this a large percentage of the time through some 400K records. So if anyone has a better way to do this, then I’d be grateful!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:00:53+00:00Added an answer on May 17, 2026 at 9:00 pm

    Remove all those += operators, they don’t make sense here. If you want to use them as a replacement for a.extend(b), then remember, that they cannot be used as an expression. This command modifies the a list, but does not return anything. So c = a.extend(b) gives nothing to c.

    Try this instead (it even does not modify original lists!):

    out = list1[:-1] + [ list1[-1] + list2[0] ] + list2[1:]
    

    returns what you want.

    • list1[:-1] is a list from list1 without the last element.
    • list1[-1] is the last element from list1.
    • list2[0] is the first element from list2.
    • list1[-1] + list2[0] is a concatenated string.
    • [ list1[-1] + list2[0] ] is a list with one element (concatenated string).
    • list2[1:] is a list from list2 without the first element.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
Specifically, I have two lists of strings that I'd like to combine into a
Ok so I have two lists in C# List<Attribute> attributes = new List<Attribute>(); List<string>
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have two lists: ask[] timeStamp[] I need to add the information in these
I have two documents with a simple schema that I need to compare: current
I have a list of numbers that i would like to send out onto
I am wondering how you would approach this problem I have two Taxrates that
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.