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

  • Home
  • SEARCH
  • 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 4030424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:28:11+00:00 2026-05-20T11:28:11+00:00

I have a list of numbers and I need to split into to corresponding

  • 0

I have a list of numbers and I need to split into to corresponding arrays of different sizes, but that make up all the combinations of the array splitting up. For example, if I have an array a=[1,2,3,4,5] and I want to split it to one array of size 3 and the other 2.

So I was thinking of making two arrays to hold each array and since there’s the same number of size 3 and size 2 arrays I could match them up and then perform my tests. (it’s a stats class so if there is a better scipy or numpy implementation I’d love to hear it as I’d like to move use those, in the end I’d like to get the all the differences of means between the different arrays)

But for my code here it is

import itertools


#defines the array of numbers and the two columns
number = [53, 64, 68, 71, 77, 82, 85]
col_one = []
col_two = []

#creates an array that holds the first four
results = itertools.combinations(number,4)

for x in results:
col_one.append(list(x))

print col_one


#attempts to go through and remove those numbers in the first array
#and then add that array to col_two
for i in range(len(col_one)):
holder = number
for j in range(4):
    holder.remove(col_one[i][j])
col_two.append(holder)  

Thanks in advance

EDIT: it seems the spacing of the code it messed up – I assure you the spacing is ok although when I run the code I can’t remove an item from the holder since it’s not there.

  • 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-05-20T11:28:12+00:00Added an answer on May 20, 2026 at 11:28 am

    I tested your code and I see the problem. In this code,

    for i in range(len(col_one)):
        holder = number
        for j in range(4):
            holder.remove(col_one[i][j])
        col_two.append(holder)
    

    the line holder = number doesn’t copy number, it just gives number a second name, holder. Then, when you remove things from holder, they’re also removed from number, so when the loop goes around again, number has four fewer numbers in it. Ad infinitum.

    You want to make a copy of number:

    for i in range(len(col_one)):
        holder = list(number)
        for j in range(4):
            holder.remove(col_one[i][j])
        col_two.append(holder)
    

    This creates a new list from number called holder. Now only holder is changed.

        holder = number[:]
    

    would also work.

    You should also use for‘s full potential by avoiding index variables:

    for num_list in col_one:
        holder = list(number)
        for num in num_list:
            holder.remove(num)
        col_two.append(holder)
    

    This does the same thing, is easier to read and probably faster to boot.

    Now for the next step, list comprehensions. This is a great way to avoid nested loops.

    for c1_list in col_one:
        c2_list = [n for n in number if n not in c1_list]
        col_two.append(c2_list)
    

    This does the same thing as above. You can even make this a one-liner:

    col_two = [[n for n in number if n not in c1_list] for c1_list in col_one]
    

    Combining it all together:

    number = [53, 64, 68, 71, 77, 82, 85]
    col_one = list(itertools.combinations(number, 4))
    col_two = [[n for n in number if n not in c1_list] for c1_list in col_one]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of numbers and need to put them all into a
I have a list of phone numbers that have been dialed (nums_dialed). I also
I have a list that has some chapter numbers in string. When I sort
i have a list of elements (let's say integers), and i need to make
I have a list of numbers between square brackets, and I need to add
I have a method returning a list of String that need to be sorted.
I have a List with numbers, and I'd like to find the position of
I have a list of numbers, for example: list=[10,50,90,60] I want to sorte the
I have a list of numbers ( integers ) (say, from 1 to 10).
I have a list of numbers which looks like this: 1.234D+1 or 1.234D-02 .

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.