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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:16+00:00 2026-05-29T05:34:16+00:00

This is part of my program for generating punnet squares. It should separate a

  • 0

This is part of my program for generating punnet squares. It should separate a “genome” of the form [[‘A’,’a’],[‘b’,’b’],[‘C’,C’]…] into possible gametes:

def gene_erator2(gen):
    gam = [[], []]
    q = 0
    for x in gen:
        q = q + 1
        if q > 1:
            gamgam = gam[:]
            for z in gam: 
                gamgam.append(z)
            gam = gamgam[:]
        for y in range(len(gam)):
            if y < len(gam)/2:
                gam[y].append(x[0])
            else:
                gam[y].append(x[1])
    return gam

When I execute

gene_erator2([['A','a'], ['B','b'], ['X','Y']])

I get

[['A', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['a', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['A', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['a', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['A', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['a', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['A', 'B', 'b', 'X', 'X', 'Y', 'Y'], ['a', 'B', 'b', 'X', 'X', 'Y', 'Y']]

instead of the expected

[['A', 'B', 'X'], ['a', 'B', 'X'], ['A', 'b', 'X'], ['a', 'b', 'X], ['A', 'B', 'Y'], ['a', 'B', 'Y'], ['A', 'b', 'Y'], ['a', 'b', 'Y']]

….What? I mean, just What?

EDIT:
I now know the function that does what I want thanks to Shang, but I still want to know what was wrong with my code….

  • 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-29T05:34:17+00:00Added an answer on May 29, 2026 at 5:34 am

    There’s a function that does what you want in the standard library.

    import itertools
    
    def gene_erator2(gen):
        return itertools.product(*gen)
    

    This returns an iterator, which lets you iterate over all the combinations.

    >>> i = gene_erator2([['A','a'],['B','b'],['X','Y']])
    >>> list(i)
    [('A', 'B', 'X'), ('A', 'B', 'Y'), ('A', 'b', 'X'), ('A', 'b', 'Y'), ('a', 'B', 'X'), ('a', 'B', 'Y'), ('a', 'b', 'X'), ('a', 'b', 'Y')]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know what you think about this part of our program is
This is the last part of the program I am working on. I want
This is part of my program: // let's get jpg image from socket int
import string ## This part of the code initializes the program by recieving inputs
I am about to create a function for a program, this is part of
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
It seems that this part of my code is where the exception occurs: c
I have been putting off developing this part of my app for sometime purely
I am trying to learn and writting this part of code. while testing few
I just started learning C but I don't understand this part of the code.

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.