File tree 2 files changed +17
-0
lines changed
Python_Data_Structures_assignments
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ file_name = input ('Enter file name:' ) #ask user for file name
2
+
3
+ file_path = open (file_name )#open the file name input given by the user
4
+ list = list ()#create a empty list
5
+
6
+ for lines in file_path :#iterate over the lines in the file
7
+ words = lines .split ()#split the line using spaces and store them in list
8
+ for i in words :#iterate the list created for each element
9
+ if i in list :continue #continue to loop if current element is in the list
10
+ list .append (i )#else add the unique element to the list
11
+
12
+ list .sort ()#sort the list alphabetically
13
+ print (list )
Original file line number Diff line number Diff line change
1
+ But soft what light through yonder window breaks
2
+ It is the east and Juliet is the sun
3
+ Arise fair sun and kill the envious moon
4
+ Who is already sick and pale with grief
You can’t perform that action at this time.
0 commit comments