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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:26:58+00:00 2026-06-08T06:26:58+00:00

I’ve reached the end of my limited knowledge with this problem. At the moment,

  • 0

I’ve reached the end of my limited knowledge with this problem. At the moment, I’m parsing diff results. Here’s an example of the results I’m trying to manipulate:

[
[[0, 0, '\xe2\x80\x9cWe are returning again statement. He depicted the attacks as part of a battle launched by Sunnis against the country\xe2\x80\x99s Shia leaders.\r\n\r\nThe first attack came about 5 a.m. on Monday when gunmen stormed onto an Iraqi '], 
[-1, 1, 'military base near the town of Duluiyah in S'], 
[0, 2, 'alahuddin Province and killed 15 Iraqi soldiers, according to security officials. Four soldiers, including a high-ranking was taken prisoner by the insurgents, who escaped with him.\r\n\r\nThe insurgents also attacked the home of a police official in Balad, seriously wounding ']], 

[[0, 4, 'eckpoint near Baquba, killing one policeman. In all, attacks were reported in at least five provinces.\r\n\r\nEight attacks were launched in Kirkuk Province, mostly targeting police patrols, with five people killed and 42 wounded.\r\n\r\nThe offensive started on the third day of the Islamic holy month of Ramadan, and '],
[-1, 5, 'apparently took advantage of the wi'], 
[1, 6, 'll and the other.']]
]

I’m building a diff summariser. Here’s how it breaks down:

The list is a list of diff results (two in the example above).

The sublist has three elements:

  • text before the change,
  • text constituting the change; and
  • text after the change.

The sub-sub-list has three elements too:

  • a number to indicate if the section is a deletion, addition or unaffected (-1,0,1 respectively);
  • a position number (sequential); and
  • the string itself.

What I need to do is to slice the strings in the sub-sub-lists, but it depends what sublist they’re in.

  • For element 1 in the sublist, I need to slice away all of the string except the last 4 characters.
  • For element 2 in the sublist, I need for there to be no slice.
  • For element 3 in the sublist, I need to slice away all of the string except the first 4 characters.

Here’s an example of why I need to slice this way. Simplified tText before the solution:

[[[...]], [[this is a],[sentence],[to demonstrate.]], [[...]]]

Text after the solution:

[[[...]], [[is a],[sentence],[to d]], [[...]]]

And the other difficulty is, I’d like to preserve the structure of the lists.

It’s been a tough day – I’d apologise for the mind bending nature of this problem, but that’s what Overflow is for…

Thoughts?

  • 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-08T06:27:00+00:00Added an answer on June 8, 2026 at 6:27 am

    You can do this with a single large unpacking assignment:

    [[[b_n, b_p, b_s[-4:]], change, [a_n, a_p, a_s[:4]]]
     for (b_n, b_p, b_s), change, (a_n, a_p, a_s) in results]
    

    An alternative would be to zip with and apply slice objects:

    [[[num, position, text[op]]
      for (num, position, text), op in zip(chunk, [slice(-4, None), slice(None), slice(4)])]
     for chunk in results]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:

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.