Splitting
One more possible task is to split the string into separate words or into separate sentences.
Surely, Python can deal with that. Use .split
method with separator as an argument (space by default). It will return a list of splits. This function also has the second argument maxsplit
defining the number of splits to do (by default - maximum possible). For example,
12print("Python, R, SQL".split(', ')) print("Hello. My name is John. I'm 31 y/o. Nice to meet you.".split('. '))
By default, this method works from left to right. Like for .strip
method, there is .rsplit
method that works from right to left.
Swipe to start coding
Given string libraries
. Split it into the list by comma as the separator (as in example).
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 4.35Awesome!
Completion rate improved to 4.35
Splitting
One more possible task is to split the string into separate words or into separate sentences.
Surely, Python can deal with that. Use .split
method with separator as an argument (space by default). It will return a list of splits. This function also has the second argument maxsplit
defining the number of splits to do (by default - maximum possible). For example,
12print("Python, R, SQL".split(', ')) print("Hello. My name is John. I'm 31 y/o. Nice to meet you.".split('. '))
By default, this method works from left to right. Like for .strip
method, there is .rsplit
method that works from right to left.
Swipe to start coding
Given string libraries
. Split it into the list by comma as the separator (as in example).
Løsning
Takk for tilbakemeldingene dine!
single
Awesome!
Completion rate improved to 4.35
Splitting
Sveip for å vise menyen
One more possible task is to split the string into separate words or into separate sentences.
Surely, Python can deal with that. Use .split
method with separator as an argument (space by default). It will return a list of splits. This function also has the second argument maxsplit
defining the number of splits to do (by default - maximum possible). For example,
12print("Python, R, SQL".split(', ')) print("Hello. My name is John. I'm 31 y/o. Nice to meet you.".split('. '))
By default, this method works from left to right. Like for .strip
method, there is .rsplit
method that works from right to left.
Swipe to start coding
Given string libraries
. Split it into the list by comma as the separator (as in example).
Løsning
Takk for tilbakemeldingene dine!