Added to maths and strings (#1642)

* Added to maths and strings

* added changes suggest by cclauss
This commit is contained in:
Cole Mollica
2020-01-08 08:18:17 -05:00
committed by Christian Clauss
parent e849578e59
commit a26ae00b24
6 changed files with 196 additions and 0 deletions

33
strings/split.py Normal file
View File

@ -0,0 +1,33 @@
def split(string: str, seperator: str = " ") -> list:
"""
Will split the string up into all the values seperated by the seperator (defaults to spaces)
>>> split("apple#banana#cherry#orange",seperator='#')
['apple', 'banana', 'cherry', 'orange']
>>> split("Hello there")
['Hello', 'there']
>>> split("11/22/63",seperator = '/')
['11', '22', '63']
>>> split("12:43:39",seperator = ":")
['12', '43', '39']
"""
split_words = []
last_index = 0
for index, char in enumerate(string):
if char == seperator:
split_words.append(string[last_index:index])
last_index = index + 1
elif index + 1 == len(string):
split_words.append(string[last_index : index + 1])
return split_words
if __name__ == "__main__":
from doctest import testmod
testmod()