Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The built-in <string>.split() procedure works
- # okay, but fails to find all the words on a page
- # because it only uses whitespace to split the
- # string. To do better, we should also use punctuation
- # marks to split the page into words.
- # Define a procedure, split_string, that takes two
- # inputs: the string to split and a string containing
- # all of the characters considered separators. The
- # procedure should return a list of strings that break
- # the source string up by the characters in the
- # splitlist.
- def split_string(source,splitlist):
- n = 0
- length = len(splitlist)
- while n < length:
- searchitem = splitlist[n]
- if searchitem in source:
- source = source.replace(searchitem,'!')
- n+=1
- return source.split('!')
- ['This', 'is', 'a', 'test', 'of', 'the', 'string', 'separation', 'code', '']
- ['After', '', 'the', 'flood', '', '', '', '', '', '', '', 'all', 'the', 'colors', 'came', 'out', '']
- ['First Name', 'Last Name', 'Street Address', 'City', 'State', 'Zip Code']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement