Solved Stage 2 — split("-") breaks LIFE-SUPPORT-4 AMAmeliaRunsOP 21 Oct, 07:41 edited I get three parts instead of two.
SASamPrice21 Oct, 08:29 Solutionreplies: 2Use rsplit with a max split of 1. It splits from the right, only once, so everything before the last dash stays together.
BEBellaRossi21 Oct, 09:22split also has maxsplit, but it works from the left. For "last separator" cases, rsplit is the tool.
Comments 4
Log in to join the discussion.
Log in Create accountUse
rsplitwith a max split of 1. It splits from the right, only once, so everything before the last dash stays together.rsplit! Didn't know it existed.
Same trick for file extensions: "archive.tar.gz".rsplit(".", 1).
splitalso hasmaxsplit, but it works from the left. For "last separator" cases, rsplit is the tool.