Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Home Forums Assignment courserra Python for Everybody – Specialization Python Data Structures Assignment 8.4, Python for Data Structure

Viewing 0 reply threads
  • Author
    Posts
    • #815
      Abhishek TyagiAbhishek Tyagi
      Keymaster

      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.py4e.com/code3/romeo.txt

        Answer
      # File name is "romeo.txt"
      fajl = raw_input("unesite ime fajla: ")
      fajlOpen = open(fajl)
      listica = []
      linije = [line.split() for line in fajlOpen]
      for i in linije:
          for j in i:
              if j not in listica:
                  listica.append(j)
      listica.sort()
      print(listica)
Viewing 0 reply threads
  • You must be logged in to reply to this topic.