Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2ab19920
Commit
2ab19920
authored
Jun 22, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make split and splitfields, join and joinfields synonyms
parent
efe5ac40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
12 deletions
+16
-12
Lib/string.py
Lib/string.py
+8
-6
Lib/stringold.py
Lib/stringold.py
+8
-6
No files found.
Lib/string.py
View file @
2ab19920
...
...
@@ -57,7 +57,8 @@ def strip(s):
# Split a string into a list of space/tab-separated words
# NB: split(s) is NOT the same as splitfields(s, ' ')!
def
split
(
s
):
def
split
(
s
,
sep
=
None
):
if
sep
is
not
None
:
return
splitfields
(
s
,
sep
)
res
=
[]
i
,
n
=
0
,
len
(
s
)
while
i
<
n
:
...
...
@@ -72,7 +73,8 @@ def split(s):
# Split a list into fields separated by a given string
# NB: splitfields(s, ' ') is NOT the same as split(s)!
# splitfields(s, '') returns [s] (in analogy with split() in nawk)
def
splitfields
(
s
,
sep
):
def
splitfields
(
s
,
sep
=
None
):
if
sep
is
None
:
return
split
(
s
)
res
=
[]
nsep
=
len
(
sep
)
if
nsep
==
0
:
...
...
@@ -89,11 +91,11 @@ def splitfields(s, sep):
return
res
# Join words with spaces between them
def
join
(
words
):
return
joinfields
(
words
,
' '
)
def
join
(
words
,
sep
=
' '
):
return
joinfields
(
words
,
sep
)
# Join fields with separator
def
joinfields
(
words
,
sep
):
# Join fields with
optional
separator
def
joinfields
(
words
,
sep
=
' '
):
res
=
''
for
w
in
words
:
res
=
res
+
(
sep
+
w
)
...
...
Lib/stringold.py
View file @
2ab19920
...
...
@@ -57,7 +57,8 @@ def strip(s):
# Split a string into a list of space/tab-separated words
# NB: split(s) is NOT the same as splitfields(s, ' ')!
def
split
(
s
):
def
split
(
s
,
sep
=
None
):
if
sep
is
not
None
:
return
splitfields
(
s
,
sep
)
res
=
[]
i
,
n
=
0
,
len
(
s
)
while
i
<
n
:
...
...
@@ -72,7 +73,8 @@ def split(s):
# Split a list into fields separated by a given string
# NB: splitfields(s, ' ') is NOT the same as split(s)!
# splitfields(s, '') returns [s] (in analogy with split() in nawk)
def
splitfields
(
s
,
sep
):
def
splitfields
(
s
,
sep
=
None
):
if
sep
is
None
:
return
split
(
s
)
res
=
[]
nsep
=
len
(
sep
)
if
nsep
==
0
:
...
...
@@ -89,11 +91,11 @@ def splitfields(s, sep):
return
res
# Join words with spaces between them
def
join
(
words
):
return
joinfields
(
words
,
' '
)
def
join
(
words
,
sep
=
' '
):
return
joinfields
(
words
,
sep
)
# Join fields with separator
def
joinfields
(
words
,
sep
):
# Join fields with
optional
separator
def
joinfields
(
words
,
sep
=
' '
):
res
=
''
for
w
in
words
:
res
=
res
+
(
sep
+
w
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment