I have a question. You see i have a file which contains data in this format:
What i want to do is to read every line and print it. However if i encounter the same word again (which is in the above case, "index") i want to print the word as well as the max number that has been read. how can i do that? So far i ve written this piece of code.
word='' cvalue='' for line in open('example.txt','r'): words=string.split(line) wordcount=len(words) if wordcount == 2: word=words cvalue=words if word == words: max_cvalue=max(words,cvalue) print word, max_cvalue
I know it is not much but i am a new user of python and i really like it :*
The thing i do not understand is how can i write in python "if you encounter the same word, then look at the value and print the word as well as the max value"
To be more specific from the above example here is what i would like to have as a result:
Any help will be deeply appreciated.