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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:59:35+00:00 2026-05-26T18:59:35+00:00

I have long text . And I’m converting this string to dict. Here is

  • 0

I have long text. And I’m converting this string to dict.

Here is code

data_dict = {}    
filter_dict = {}    
for each in text.split("\n"):
    temp = each.split('=')
    if len(temp) == 2:
        data_dict[temp[0]] = temp[1]
data = dict((k.strip(), v.strip()) for k, v in data_dict.iteritems())

Here is output which is convert from text to dict

 {'producer': 'Sailadhar Baruah', 
'image': 'paporithefilm.jpg', 
'distributor': '', 
'alt': '',
 'image size': '',
 'gross': '', 
 'writer': 'Jahnu Barua',
 'cinematography': 'Binod Pradhan', 
 'music': 'Satya Baruah P. P. Vidyanathan',
 'followed by': '', 
 'narrator': '', 
 'director': 'Jahnu Barua', 
 'released': '1986',
 'studio': 'Dolphin s Pvt. Ltd',
 'starring': 'Gopi Desai Biju Phukan Sushil Goswami Chetana Das Dulal Roy',
 'editing': '', 
 'name': 'Papori', 
 'language': 'Assamese languageAssamese', 
 'country': 'Assam, IND', 'budget': '', 
 'caption': 'A Screenshot',
 'preceded by': '', 
 'runtime': '144 minutes'}

I just want to know where is my last paragraph gone? Can I store last paragraph text to any varible? thanks

  • 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-26T18:59:35+00:00Added an answer on May 26, 2026 at 6:59 pm

    As has been pointed out, you are only matching when you have a key = value format. Try something like this instead.

    text = file("text.txt", "r").readlines()
    
    skip_keys = ('film', '')
    data_dict = {}
    for each in text:
        temp = [x.strip() for x in each.split('=')]
        if temp[0] in skip_keys:
            continue
        if len(temp) == 2:
            data_dict[temp[0]] = temp[1]
        else:
            data_dict['no_key'] = temp[0]
    print data_dict
    

    Here, your paragraph will be added to ‘no_key’. I started out my answer using a defaultdict from the collections module, and setting the value to be lists so you could track any unkeyed values, but, if your format is consistent, then the above should work.

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

Sidebar

Related Questions

It have source code that contains sections like this: <pre> text </pre> long long
I have this: <ul> <li> <p>Some long text here</p> </li> </ul> is there a
I have a long text string (including \n newline characters) that I feed into
Say I have a long string of text, and I want to capture every
I have the following code: <marquee><p>{a long text}</p></marquee> The text within the marquee appears
I have this JQuery function: $(document).ready(function() { $(div.descript_long).each(function() { var descript_length = $(div.descript_long).text().length; if(descript_length
I have long text containing name that looks like something-something. This long text is
I have a button with long text like Click here to start playing. I
I have a long string of text delimited by a character (pipe character). I
I have a long text and I'd like to offer the user a reading

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.