0

I have the following string a = "1.MATCHES_$TEXT$$STRING"

I want to create a function which at some point calls the split function. My function looks like this:

def myfunction(x,splt,sel_nr,col=False):
    if(not col):   
         return(x.split(splt)[sel_nr]

My question is that this: a.split('$')[0:2] works, but this:

myfunction(x=a,splt='$',sel_nr=[0:2],col=False) does not and I do not understand why.

I also tried:

def myfunction(x,splt,*sel_nr,col=False):
    if(not col):   
         return(x.split(splt)[sel_nr]

but it still does not work

I am using python 3.x

1 Answer 1

1

You can't do this! sel_nr is invalid, you can do it with follow way!

def myfunction(x,splt,start, end,col=False):
     if not col:   
          return(x.split(splt)[start: end])

myfunction(x=a,splt='$',start=1, end=3,col=False)
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.