-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiplist.py
More file actions
56 lines (48 loc) · 1.82 KB
/
piplist.py
File metadata and controls
56 lines (48 loc) · 1.82 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pip test
import math
result = math.e != math.pow(2, 4)
print(int(result))
for ch in "ace":
print(chr(ord(ch) + 1), end=" ")
def mysplit(strng):
# return [] if string is empty or contains whitespaces only
if strng == '' or strng.isspace():
return [ ]
# prepare a list to return
lst = []
# prepare a word to build subsequent words
word = ''
# check if we are currently inside a word (i.e., if the string starts with a word)
inword = not strng[0].isspace()
# iterate through all the characters in string
for x in strng:
# if we are currently inside a string...
if inword:
# ... and current character is not a space...
if not x.isspace():
# ... update current word
word = word + x
else:
# ... otherwise, we reached the end of the word so we need to append it to the list...
lst.append(word)
# ... and signal a fact that we are outside the word now
inword = False
else:
# if we are outside the word and we reached a non-white character...
if not x.isspace():
# ... it means that a new word has begun so we need to remember it and...
inword = True
# ... store the first letter of the new word
word = x
else:
pass
# if we left the string and there is a non-empty string in word, we need to update the list
if inword:
lst.append(word)
# return the list to invoker
return lst
print(mysplit("To be or not to be, that is the question"))
print(mysplit("To be or not to be,that is the question"))
print(mysplit(" "))
print(mysplit(" abc "))
print(mysplit(""))