Skip to content

Instantly share code, notes, and snippets.

@airvzxf
Created February 23, 2023 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airvzxf/5526d51c25ab931fffbf63db89dc127d to your computer and use it in GitHub Desktop.
Save airvzxf/5526d51c25ab931fffbf63db89dc127d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Convert String into Array of Strings.
"""
from doctest import testmod
# Press CTR+Q to see the documentation.
def string_split(text: str, delimiter: str) -> list[str]:
"""
Split the text by words.
>>> string_split("a b c d", " ")
['a', 'b', 'c']
:rtype text: str
:param text: Text which contains a lot of words.
:rtype delimiter: str
:param delimiter: The character or characters which indicate where it will be split.
:rtype: list[str]
:return: List of splitted the words.
"""
return text.split(delimiter)
if __name__ == '__main__':
words = "a/apple/arm/basket/bread/car/camp/element/..."
split_char = '/'
elements = words.split(split_char)
# elements = string_split(words, split_char)
for word in elements:
print(f"Word: {word}")
# testmod()
# Or run: `python -m doctest -v main.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment