I am working on a project in Python and trying to separate a list of words out into alphabetical files. So any word starting with 'a' or 'A' would go into an 'A.html' file. I am able to create the file and have all the words that start with the letter, but I need to do it recursively so that it will go through all the letters and put them into different files. Here is some of the code: class LetterIndexPage(object):
def __init__(self, wordPage):
self.alphaList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Numbers','Special Characters']
def createLetterPages(self):
if not os.path.exists('A.html'):
file('A.html', 'w')
letterFileName = 'A.html'
letterItemList = []
for item in wordItems():
if item[:1] == 'a' or item[:1] == 'A':
letterItemList.append(item)
letterItems = reduce(lambda letterItem1, letterItem2: letterItem1 + letterItem2, letterItemList)
return letterItems
The wordItems() method returns all the text from a web page. I am not sure where to go from here. Can anyone help?
should work I think (without testing it...)