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 8722499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:26:07+00:00 2026-06-13T07:26:07+00:00

I am trying to put a file in a dictionary. The file is like

  • 0

I am trying to put a file in a dictionary.
The file is like this:

1 some something something
2 go goforit doit 
17 non so 

I am trying something like this but is doesnt work:

def filetodic():
 d={}
 with open("file.txt") as f:
  for line in f:
   key  = line.split()
 return d
print filetodic()

EDIT: The key for every field in the dictionary needs to be the number that appears to be the first element in each line in the file.

  • 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-13T07:26:08+00:00Added an answer on June 13, 2026 at 7:26 am

    Try this:

    def filetodic():
        d={}
        f = open("file.txt")
        for line in f:
            key  = line.split()
            d[key[0]]= ' '.join(key[1:])
        return d
    
    print filetodic()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to put some word in tempfile via commandline temp file creat
I'm trying to put <!CDATA> in a specific tag in my XML file, but
Greeting, I'm trying to put some Beanshell script in my Ant build.xml file. I've
I'm trying to put into XML-file some data. Here is the code: @Test public
I'm trying to put the content of a file into a variable, but I'm
I am trying to put the content of a file into a variable, this
I am trying to put something in my .htaccess file that will allow me
I am trying to put a PSD file on my form using Microsoft report
I got this traceback when trying to upload a file using put_file (source code
I am trying to put a log.txt file on the root of my application

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.