Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9286307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:23:10+00:00 2026-06-18T19:23:10+00:00

I have a text file with entries that look like this : JohnDoe Assignment

  • 0

I have a text file with entries that look like this :

JohnDoe

Assignment 9  
Reading: NO  
header: NO  
HW: NO  
Solutions: 0 
show: NO  
Journals: NO  
free: NO  
Finished: NO  
Quiz: 0  
Done     
Assignment 3  
E-book: NO  
HW: NO  
Readings: NO  
Show: 0  
Journal: NO 
Study: NO  
Test: NO  
Finished: NO  
Quiz: 0  
Done

This is a small sample. The file has several students in it. Each student has two assignments under their name and they only pass if the line that starts with “Finished” in each assignment reads “Finished: YES”. All of the data under each assignment is disorganized, but somewhere under each assignment a line will say “Finished: YES (or NO)” I need a way to read the file and say whether or not any of the students have passed. So far, I have

def get_entries( file ):
with open( "dicrete.txt.rtf", 'rt') as file:
    for line in file:
        if "Finished" in line:
            finished, answer = line.split(':')
            yield finished, answer

# dict takes a sequence of  `(key, value)` pairs and turns in into a dict
print dict(get_entries( file ))

I can only get this code to return a single entry (the first “Finished” it reads as key and “YES or NO” as value, which is what I want, but I want it to return Every line in the file that that starts with “Finished”. So the sample data I provided I want to return a dict with 2 entries {Finished:”NO” , Finished:”NO”}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:23:11+00:00Added an answer on June 18, 2026 at 7:23 pm

    Dictionaries can only store one mapping per key. So, you can never have a dictionary that has two different entries for the same key.

    Consider using a list of two-tuples instead, like [("Finished", "NO"), ("Finished", "NO")].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file with hundreds of entries formatted like this, I need
I have a text file containing entries like this: @markwarner VIRGINIA - Mark Warner
I have a big text file which contains similar entries like this My goal
I have text file with entries like 123 112 3333 44 2 How to
I have text file with some stuff that i would like to put into
I' ve got a problem with Haskell. I have text file looking like this:
I have a text file that contains around 21 lac entries and I want
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
I have 2 plain text files that contain some words, like: File 1 Aarhus
I have a text file that has one colunm of 1800 entries that are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.