Skip to content

Instantly share code, notes, and snippets.

View drashtishah30's full-sized avatar

DRASHTI SHAH drashtishah30

  • Ahmedabad, Gujarat, India
  • 18:21 (UTC -12:00)
View GitHub Profile
@drashtishah30
drashtishah30 / gist:47e92d6e8b61fc770f9b79efabb2ddcd
Created July 18, 2020 05:08 — forked from tombrad/gist:4697060
8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() function. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words …
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list() # list for the desired output
for line in fh: # to read every line of file romeo.txt
word= line.rstrip().split() # to eliminate the unwanted blanks and turn the line into a list of words
for element in word: # check every element in word
if element in lst: # if element is repeated
continue # do nothing
else : # else if element is not in the list
lst.append(element) # append