I am stuck on a problem with no idea how to start.
I need to create a program that creates a file witha index that tells you which line of the file each word appears on.
i Have this so far but i may be way off.

t = open(""),"r")
    def findWord(aline):
        wordDict = {}
        for item in aline
            if item in wordDict
            wordDict [item] = wordDict[item] +1
            return wordDict
6 Years
Discussion Span
Last Post by pyTony

I am not sure if i stated the problem right. I need to come up with alist that tells where every word in the list is located. The list should be in alphabeticallt order, witha series of line numbers following each word.

Import # keywords are lower case, objects upper case in Python by convention, what is purpose of this variable
t = open(""),"r") # where is this variable used, don't you think that opening and closing parenthesis should be equal number
    def findWord(aline):# blocks are indented after line with :, not before
        wordDict = {} # empty dictionary for each line ?
        for item in aline # : missing, item is first character/item of aline
            if item in wordDict # never True as wordDict (should be word_dict by convention) is empty, : and indent missing
            wordDict [item] = wordDict[item] +1 # what about the first item and how you know it's place, like you say you want to save that, not count
            return wordDict # leave function returning dictionary after fist item in line
# function never called

Maybe you could use some practise interactively at Python prompt and writing functions in editor and calling them.

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.