Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

split at the second occurrence of the element python

def hyphen_split(a):
    if a.count("-") == 1:
        return a.split("-")[0]
    return "-".join(a.split("-", 2)[:2])

>>> hyphen_split("some-sample-filename-to-split")
'some-sample'
>>> hyphen_split("some-sample")
'some'
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #split #occurrence #element #python
ADD COMMENT
Topic
Name
4+1 =