String Rsplit in Python

Level 257 keystrokes

This splits a string from the right, limiting to 1 split.

Python code

# Create a string with three "-" separators
1text = "a-b-c-d"
# rsplit("-", 1) splits from the right, at most once (maxsplit=1)
# Only the last "-" is used, so everything before it stays together
2parts = text.rsplit("-", 1)
# Prints ['a-b-c', 'd']
3print(parts)

Output

['a-b-c', 'd']
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • -× 4
  • "× 4
  • (× 2
  • )× 2
  • =× 2
  • ,× 1
  • .× 1

More Python examples at level 2

← Python typing practice