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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:41:31+00:00 2026-06-13T11:41:31+00:00

Possible Duplicate: Reading a File into a Dictionary And Keeping Count I am trying

  • 0

Possible Duplicate:
Reading a File into a Dictionary And Keeping Count

I am trying to create a dictionary with two values: the first value is the text:

<NEW ARTICLE>
Take a look at 
what I found.
<NEW ARTICLE>
It looks like something
dark and shiny.
<NEW ARTICLE>
But how can something be dark
and shiny at the same time?
<NEW ARTICLE>
I have no idea.

and the second value is the count of how many times the word “ARTICLE>” is used.

I tried different methods and one method I received this error:

The erorr I receive is this:

(key, val) = line.split()
ValueError: need more than 1 value to unpack

I’ve tried a few different methods but to no avail, one method I tried said it gave too many values to unpack..

I want to be able to search for a key/word in the dictionary later on and find its appropriate count.

Using Python 3.

  • 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-13T11:41:32+00:00Added an answer on June 13, 2026 at 11:41 am

    this should do it:

    >>> with open("data1.txt") as f:
    ...     lines=f.read()
    ...     spl=lines.split("<NEW ARTICLE>")[1:]
    ...     dic=dict((i,x.strip()) for i,x in enumerate(spl))
    ...     print dic
    ... 
    {0: 'Take a look at \nwhat I found.',
     1: 'It looks like something\ndark and shiny.',
     2: 'But how can something be dark\nand shiny at the same time?',
     3: 'I have no idea.'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Reading the last n lines from a huge text file I have
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Reading csv file I have a comma delimited file: Some Text, More
Possible Duplicate: reading a specific file from sdcard in android I'm trying to make
Possible Duplicate: Reading in a text file in iOS This is a really dumb
Possible Duplicate: android reading from a text file So I need to load text,
Possible Duplicate: Inserting PHP array into Javascript array I'm reading a file in server
Possible Duplicate: Java: Reading integers from a file into an array I want to
Possible Duplicate: Reading from text file until EOF repeats last line c++ EOF running
Possible Duplicate: Reading dll.config (not app.config!) from a plugin module. I have two different

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.