forked from mckrd/py_repo_beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeListofCSV
36 lines (36 loc) · 1.08 KB
/
MakeListofCSV
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
def format_words(words):
#first remove commas if any
for item in words or []:
if item == ',':
for item in range(words.count(',')):
words.remove(',')
else:
pass
#then remove spaces if any
for item in words or []:
if item == '':
for item in range(words.count('')):
words.remove('')
else:
pass
if not words:
return ''
else:
result = ''
y = len(words)
count = 0
for x in words:
if y == 1:
result += x
#adding first word to result if it's not the only word
elif count == 0 and count < y-1:
result += str(x)
count += 1
elif count > 0 and count < y-1 and x != ',':
#result += ', '.join(map(str, words))
result += ', ' + str(x)
count += 1
else:
result += ' and ' + str(words[y-1])
return (result)
print (format_words(['ninja', 'samurai', 'ronin']))