forked from RoksYz/CS1301xIII---Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordLength2.py
More file actions
28 lines (20 loc) · 766 Bytes
/
Copy pathWordLength2.py
File metadata and controls
28 lines (20 loc) · 766 Bytes
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
def length_words(astring):
replacex ='?.,!"'
for item in replacex:
astring = astring.replace(item,"")
astring = astring.lower()
astring = astring.split()
Resultdict = {}
for items in astring:
value = len(items)
if value not in Resultdict:
Resultdict[value]=[items]
else:
Resultdict[value].append(items)
return Resultdict
#print:
#{1: ['i', 'a', 'a'], 2: ['of', 'of'], 3: ['ate', 'out', 'dog'], 4: ['bowl', 'bowl'], 5: ['today'], 6: ['cereal']}
#
#The keys may appear in a different order, but within each
#list the words should appear in the order shown above.
print(length_words("I ate a bowl of cereal out of a dog bowl today."))