Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Data Structures_Coursera_Assignment 8.4 #4

Open
fairypp opened this issue Jun 26, 2016 · 0 comments
Open

Python Data Structures_Coursera_Assignment 8.4 #4

fairypp opened this issue Jun 26, 2016 · 0 comments

Comments

@fairypp
Copy link
Owner

fairypp commented Jun 26, 2016

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() method. 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 in alphabetical order.
You can download the sample data at http://www.pythonlearn.com/code/romeo.txt

fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
    line.rstrip()
    words=line.split()
    for i in range(len(words)):
        if words[i] not in lst:
            lst.append(words[i])
lst.sort()
print lst
@fairypp fairypp changed the title Programming for Everybody (Getting Started with Python)_Coursera_Assignment 8.4 Python Data Structures_Coursera_Assignment 8.4 Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant