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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:15:58+00:00 2026-06-12T12:15:58+00:00

I have a list of lists and a separator string like this: lists =

  • 0

I have a list of lists and a separator string like this:

lists = [
    ['a', 'b'],
    [1, 2],
    ['i', 'ii'],
]
separator = '-'

As result I want to have a list of strings combined with separator string from the strings in the sub lists:

result = [
    'a-1-i', 
    'a-1-ii', 
    'a-2-i', 
    'a-2-ii',
    'b-1-i', 
    'b-1-ii', 
    'b-2-i', 
    'b-2-ii',
]

Order in result is irrelevant.

How can I do this?

  • 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-12T12:16:00+00:00Added an answer on June 12, 2026 at 12:16 pm
    from itertools import product
    result = [separator.join(map(str,x)) for x in product(*lists)]
    

    itertools.product returns an iterator that produces the cartesian product of the provided iterables. We need to map str over the resultant tuples, since some of the values are ints. Finally, we can join the stringified tuples and throw the whole thing inside a list comprehension (or generator expression if dealing with a large dataset, and you just need it for iteration).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of strings like this FirstName-Lastname (separated by a dash -) I
I have a list that looks like this: [ 'A', 'must', 'see', 'is', 'the',
I have a query that produces a result like this: The data is sorted
I have a string ($c) that contains a comma-separated list of settings. Some settings
Quick question, I have the following string which is a coma separated list of
I have a string that represents a list of tags separated by space. It
I have a function like this: private void GetRSS(int start, int end) { for
I have the following list of lists: sweet = [['1234-4321-1',[5, 6, -4, 11, 22]],
I have two lists comprised of different complex-objects, and each one is from 2
I have a XML file like this: <Document> <Tests Count=4> <Test> <Name>test with a</Name>

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.