Created
February 23, 2023 08:02
-
-
Save airvzxf/5526d51c25ab931fffbf63db89dc127d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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