3

I have a python function as below. I want to call the function in C# and pass the 2 list arguments? It returns a ranked list. Is this possible and how? thanks for your help

function ranking_option() #accepts two arguments:
  def Ranking_Options(costs, savings):
  ##Lets us form a list of list from the supplied data

  rearranged_list = sorted([[costs[i], savings[i]] for i in range(len(costs))], reverse=False)
  rankedlist = [rearranged_list[0]] #We form a new list of the ranked data coordinates 

  #Examine the sorted list one by one
  for pair in rearranged_list[1:]:

        if pair[0]>=rankedlist[-1][0] and pair[1]>=rankedlist[-1][1]:
            rankedlist.append(pair)
            if rankedlist[-2][0]==rankedlist[-1][0] and rankedlist[-2][1]<=rankedlist[-1][1]:
                rankedlist[-2],rankedlist[-1]=rankedlist[-1],rankedlist[-2]
        else:

            if pair[0]==rankedlist[-1][0] and pair[1]>=rankedlist[-1][1]:
               rankedlist[-1]=pair
            rankedlist.append(pair)
return rankedlist
2
  • You should have a look at IronPython ironpython.net Commented May 17, 2013 at 15:04
  • 1
    Why not rewrite it in C#? That way you can introduce some annoymous types rather than rely on arrays all the time. Commented May 17, 2013 at 15:40

1 Answer 1

2

I have a post on my blog about calling a Python COM server from C#. It should help in what you are trying to do. COM will make the interop easier, but it takes a bit of work to set it up. http://www.midniteblog.com/?p=64

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.