FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python-algorithm/strings/split.py at master · rasata/Python-algorithm · GitHub
rasata
/
Python-algorithm
Public
forked from
TheAlgorithms/Python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python-algorithm
/
strings
/
split.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (27 loc) · 937 Bytes
Breadcrumbs
Python-algorithm
/
strings
/
split.py
Copy path
File metadata and controls
37 lines (27 loc) · 937 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def
split
(
string
:
str
,
separator
:
str
=
" "
)
->
list
:
"""
Will split the string up into all the values separated by the separator
(defaults to spaces)
>>> split("apple#banana#cherry#orange",separator='#')
['apple', 'banana', 'cherry', 'orange']
>>> split("Hello there")
['Hello', 'there']
>>> split("11/22/63",separator = '/')
['11', '22', '63']
>>> split("12:43:39",separator = ":")
['12', '43', '39']
>>> split(";abbb;;c;", separator=';')
['', 'abbb', '', 'c', '']
"""
split_words
=
[]
last_index
=
0
for
index
,
char
in
enumerate
(
string
):
if
char
==
separator
:
split_words
.
append
(
string
[
last_index
:
index
])
last_index
=
index
+
1
if
index
+
1
==
len
(
string
):
split_words
.
append
(
string
[
last_index
:
index
+
1
])
return
split_words
if
__name__
==
"__main__"
:
from
doctest
import
testmod
testmod
()
Back
|
FazBrowse Home
|
New Git URL