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

  • SEARCH
  • Home
  • 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 4104368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:06:34+00:00 2026-05-20T21:06:34+00:00

I recently asked a question about converting list of values from txt file to

  • 0

I recently asked a question about converting list of values from txt file to dictionary list. You can see it from the link here: See my question here

P883, Michael Smith, 1991
L672, Jane Collins, 1992

(added)
(empty line here)
L322, Randy Green, 1992
H732, Justin Wood, 1995(/added)
^key ^name ^year of birth

===============
this question has been answered and i used the following code (accepted answer) which works perfectly:


def load(filename): students = {}

   infile = open(filename)
   for line in infile:
       line = line.strip()
       parts = [p.strip() for p in line.split(",")]
       students[parts[0]] = (parts[1], parts[2])
   return students 

however when there is a line space in the values from the txt file.. (see added parts) it doesnt work anymore and gives an error saying that list index is out of range.

  • 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-05-20T21:06:34+00:00Added an answer on May 20, 2026 at 9:06 pm

    Check for empty lines inside your for-loop and skip them:

    for line in infile:
        line = line.strip()
        if not line:
            continue
        parts = [p.strip() for p in line.split(",")]
        students[parts[0]] = (parts[1], parts[2])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently asked a question on StackoverFlow about the MVC: Can the MVC Design
Recently I asked a question on stackoverflow about multiline tabs. Below is the link
I recently asked a question here on Stack Overflow about how to cast my
A question was asked recently about removing SourceSafe integration from Visual Studio 6 .
I recently asked a question about committing a new file but now I am
I recently asked a question about formatting JavaScript code in Vim. And I've also
I've recently asked a question about clipping an image via path at view's drawRect
Recently I have asked a question about what I should use to create self-contained
Note: I originally asked this question about an hour ago but only recently realized
So recently, I asked a question about a class I created that extended SQLiteOpenHelper

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.