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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:52:35+00:00 2026-05-10T23:52:35+00:00

What would be the best way to do this. The input string is <133_3><135_3><116_2>The

  • 0

What would be the best way to do this.

The input string is

<133_3><135_3><116_2>The other system worked for about 1 month</116_2> got some good images <137_3>on it then it started doing the same thing as the first one</137_3> so then I quit using either camera now they are just sitting and collecting dust.</135_3></133_3> 

the expected output is

{'The other system worked for about 1 month got some good images on it then it started doing the same thing as the first one so then I quit \ using either camera now they are just sitting and collecting dust.':[133, 135],  'The other system worked for about 1 month': [116],  'on it then it started doing the same thing as the first one':[137]  } 

that seems like a recursive regexp search but I can’t figure out how exactly.

I can think of a tedious recursive function as of now, but have a feeling that there should be a better way.

Related question: Can regular expressions be used to match nested patterns?

  • 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. 2026-05-10T23:52:36+00:00Added an answer on May 10, 2026 at 11:52 pm

    Use expat or another XML parser; it’s more explicit than anything else, considering you’re dealing with XML data anyway.

    However, note that XML element names can’t start with a number as your example has them.

    Here’s a parser that will do what you need, although you’ll need to tweak it to combine duplicate elements into one dict key:

    from xml.parsers.expat import ParserCreate  open_elements = {} result_dict = {}  def start_element(name, attrs):     open_elements[name] = True  def end_element(name):     del open_elements[name]  def char_data(data):     for element in open_elements:         cur = result_dict.setdefault(element, '')         result_dict[element] = cur + data  if __name__ == '__main__':     p = ParserCreate()      p.StartElementHandler = start_element     p.EndElementHandler = end_element     p.CharacterDataHandler = char_data      p.Parse(u'<_133_3><_135_3><_116_2>The other system worked for about 1 month</_116_2> got some good images <_137_3>on it then it started doing the same thing as the first one</_137_3> so then I quit using either camera now they are just sitting and collecting dust.</_135_3></_133_3>', 1)      print result_dict 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 96k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Javascript has no access to client OS to check if… May 11, 2026 at 7:17 pm
  • Editorial Team
    Editorial Team added an answer I often use pdfinfo There is also pdffonts to display… May 11, 2026 at 7:17 pm
  • Editorial Team
    Editorial Team added an answer using dir() and imp module May 11, 2026 at 7:17 pm

Related Questions

I would like to know what would be the best way to do unit
What would be the best way to implement a simple crash / error reporting
I'm trying to figure out what would be the best way to have a
Binary tree http://img9.imageshack.us/img9/9981/binarytree.jpg What would be the best way to serialize a given binary

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.