File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ '''Open the file romeo.txt & read it line by line.
2+ For each line split the line into a list of words using split() method.
3+ The program should build a list of words.
4+ For each word on each line check to see if he word is already in the list & if not append it to the list.
5+ When the program completes, sort & print the resulting words in python sort() order.
6+ FILE: romeo.txt
7+ WEB LINK: http://www.py4e.com/code3/romeo.txt'''
8+
9+ name = input ('Enter the file name: ' )
10+ file = open (name )
11+ count = 0
12+ word = []
13+ line_list = []
14+ word_list = []
15+ for line in file :
16+ line = line .rstrip ()
17+ line_list .append (line )
18+ word = line_list [count ].split ()
19+ for i in word :
20+ if i not in word_list :
21+ word_list .append (i )
22+ count += 1
23+
24+ word_list .sort ()
25+ print (word_list )
You can’t perform that action at this time.
0 commit comments