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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:58:05+00:00 2026-06-13T17:58:05+00:00

I have a pretty simple idea in mind but don’t exactly know how to

  • 0

I have a pretty simple idea in mind but don’t exactly know how to go about doing it. I have two lists of different length (say 50 in one and 200 in the other).

so

len(x) = 50
len(y) = 200

What I want to do is print out some lines where one value from x corresponds to multiple values of y (does not matter if numbers are repeated).

I.e. suppose x = [1,2,3,4]
y = [7,8,9,10,11,12,13,14,15,16,17]

I want to print out:
1: 7
1: 8
1: 9
1: 10
2: 11
2: 12
2: 13
3: 14
3: 15
3: 16
4: 17

Randomization of values from y does not really matter.
It does not matter how many multiple values get printed out for each value of x. I am basically trying to write a sql script of inserting multiple elements from one table into another and using python to write the script.

I know this can be done by simply iterating over the smallest list and having multiple f.write() statements while incrementing some variable to have multiple values of y associated to a single value of x. But this does not cover all the values of y and looks kind of silly. Is there a better way to go about doing this?

Edit: For the question where how I came up with the association of keys to values, it does not really matter how many values 1 key is associated with (an upper bound of 8 exists). There can be only 1 value or multiple (up to 8). Then again, there can be repetitions of values between keys (i.e. in my example there is not but key 4 can say have values 7/8 also)

  • 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-13T17:58:07+00:00Added an answer on June 13, 2026 at 5:58 pm

    Try this Python solution:

    >>> x = [1,2,3,4]
    >>> y = [7,8,9,10,11,12,13,14,15,16,17]
    >>> lnx, lny = len(x), len(y)
    >>> groupatleast = (lny + lnx - 1) // lnx
    >>> x2y = {}
    >>> for i in range(lnx):
        x2y[x[i]] = y[i*groupatleast: (i+1)*groupatleast]
    
    
    >>> x2y[x[i]] += y[(i+1)*groupatleast:]
    >>> for x1,ylist in sorted(x2y.items()):
        for y1 in ylist:
            print ("%i: %i" % (x1, y1))
    
    
    1: 7
    1: 8
    1: 9
    2: 10
    2: 11
    2: 12
    3: 13
    3: 14
    3: 15
    4: 16
    4: 17
    >>> 
    >>> # Help:
    >>> lnx, lny
    (4, 11)
    >>> groupatleast
    3
    >>> x2y
    {1: [7, 8, 9], 2: [10, 11, 12], 3: [13, 14, 15], 4: [16, 17]}
    >>> ylist
    [16, 17]
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm having this problem, it should be pretty simple, but I don't know
I have a pretty simple case which I started solving using foreach(), but then
I have a pretty simple question, but for some reason I am drawing a
I have a pretty simple problem, but right now can't seem to see the
I have a pretty simple console project with an entity model (containing two simple
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
i have pretty simple simple question (i hope so). How do i change the
I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a pretty simple Linq to XML query: var q = from c

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.