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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:17:45+00:00 2026-05-13T13:17:45+00:00

My ultimate aim is to convert the below code in python to C#, but

  • 0

My ultimate aim is to convert the below code in python to C#, but I’d like to do it my self by learning the python syntax. I understand that the code is recursive.

The code produces polynomials of degree n with k variables. More specifically the list of exponents for each variable.

def multichoose(n,k):
    if k < 0 or n < 0: return "Error"
    if not k: return [[0]*n]
    if not n: return []
    if n == 1: return [[k]]
    return [[0]+val for val in multichoose(n-1,k)] + \
        [[val[0]+1]+val[1:] for val in multichoose(n,k-1)]

Here is the conversion I have so far:

public double[] MultiChoose(int n, int k)
{
    if (k < 0 || n < 0)
    {
         throw new Exception();
    }

   if (k == 0)
   {
       return [[0]*n]; // I have no idea what the [[0]*n] syntax means
   }

   if (n == 0)
   {
       return new double[0]; // I think this is just an empty array
   }

   if (n == 1)
   {
       return new double[1] {k}; // I think this is just an empty array
   }

   //Part I don't understand
   return [[0]+val for val in MultiChoose(n-1,k)] + \
        [[val[0]+1]+val[1:] for val in MultiChoose(n,k-1)]
} 

My question is: How do I convert the python 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-13T13:17:45+00:00Added an answer on May 13, 2026 at 1:17 pm

    I would use LINQ in C# to translate the code:

    • [] is the empty list.

      Enumerable.Empty<T>()
      
    • [x] is the list containing a single item, x.

      Enumerable.Repeat(x, 1)
      
    • [[0]*n] is the list containing the list containing n copies of 0.

      Enumerable.Repeat(Enumerable.Repeat(0, n), 1)
      
    • [X for Y in Z] is a list comprehension.

      from Y in Z select X
         - or -
      Z.Select(Y => X);
      
    • X + Y (where X and Y are lists) is list concatenation.

      Enumerable.Concat(X, Y)
      

    The signature of MultiChoose would be:

     public IEnumerable<IEnumerable<double>> MultiChoose(int n, int k);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Why not try Ruby or Python? That's what I did,… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer It seems when calling delay (or any other animations for… May 14, 2026 at 10:59 pm
  • Editorial Team
    Editorial Team added an answer You can use: MSBuild.Community.Tasks.IIS library, there will be WebBase.IISVersion, it… May 14, 2026 at 10:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.