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 8525501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:59:46+00:00 2026-06-11T07:59:46+00:00

Say I have two lists [16, 0, 0, ‘;’, 17, 0, 2, ‘;’, 0,

  • 0

Say I have two lists

[16, 0, 0, ';', 17, 0, 2, ';', 0, 2, 1, ';']
  [-1, 0, ';', 0, -2, ';', -2, -1, ';']

Is there a simpler way to merge these list elements conditionally on meeting the ‘;’ character than individually iterating through them both and combining them?

The output should be

[16, 0, 0, -1, 0, ';', 17, 0, 2, 0, -2, ';', 0, 2, 1, -2, -2,';']
  • 1 1 Answer
  • 0 Views
  • 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-06-11T07:59:48+00:00Added an answer on June 11, 2026 at 7:59 am
    def get_part(lst,sep=';'):
        out = []
        for i in lst:
            if i == sep:
               yield out
               out = []
            else:
               out.append(i)
    

    Now we can zip together your lists:

    merged = []
    for l1,l2 in zip(get_part(list1),get_part(list2)):
        merged.extend(l1)
        merged.extend(l2)
        merged.append(';')
    

    Of course, at it’s core, this is essentially iterating over both of them and combining … so in answer to your question, I don’t think there’s a better way.


    Perhaps a better way to store your lists would be storing them as a list of lists — e.g.:

    list1 = [[16, 0, 0], [ 17, 0, 2], [ 0, 2, 1] ]
    

    stored like this, you can just do:

    merged = [ l1 + l2 for l1,l2 in zip(list1,list2) ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a list somewhere called majorPowers which contain these two lists:
Say you have a std::list of some class. There are two ways you can
I am trying to merge two list in parallel. I have two sorted lists
let's say I have two lists: a = list(1,2,3) b = list(4,5,6) So I
Say I have two lists: a = list(1,2) b = list(x,y) #a #[[1]] #[1]
Say I have two lists or arrays of strings. For example: list 1: a,
Say I have two lists: List<CanidateSkill> canidateSkills; List<JobDesiredSkill> desiredSkills; class CanidateSkill { public Guid
I have two generic lists. Let's say they are List< A > and List<
Say I have two lists val L1 = List[(Int, Int)]((1,1), (2,2)) val L2 =
Say I have two lists: List((a,1),(b,4),(d,5),(a,7),(b,6)) and List(a,b,c,d) and I want to group them

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.