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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:55:30+00:00 2026-05-18T09:55:30+00:00

Consider the string ( treat it as an array of digits ) 0 0

  • 0

Consider the “string” ( treat it as an array of digits )

0 0 1 8 8 8 1 0

The RLE ( “groupby” ) is:

[(0,2), (1, 1), (8,3), (1, 1), (0, 1)]

We then enrich the above RLE with the sum of the run lengths of the previous elements.

Hence, the enriched version of the above becomes:

[(0, (0,2)), (0+2, (1, 1)), (0+2+1, (8,3)), (0+1+2+3, (1, 1)), (0+1+2+3+1, (0, 1))]

The “string” split on 1:

0 0 , 8 8 8 , 0

RLE split on 1

[(0,2)] , [(8,3)] , [(0, 1)]

The “string” split on 8:

0 0 1 , , , 1 0

RLE split on 8

[(0,2), (1, 1)] , , , [(1, 1), (0, 1)]

Note : In my examples, I have cited the “RLE split on Z” lists without enriching them. This would not be so. I left them out to reduce clutter. For example, the “RLE split on 1” should really be treated as:

[(0, (0,2))] , [(0+2+1, (8,3))] , [(0+1+2+3+1, (0, 1)]

How can I achieve this “RLE split” on Z ( = 1, 8; in this case )

It’s fine to leave out empty arrays ( after split ).

Perhaps a clever list comp.? ( it seems a little easier to solve with a for loop with an append nested within )

  • 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-18T09:55:30+00:00Added an answer on May 18, 2026 at 9:55 am

    Just for show the way how, I strongly advise you not to use this

    “elegant” ugly way:

    >>> data
    [0, 0, 1, 8, 8, 8, 4, 4, 1, 0]
    >>> def fromDataToSplitRLE(dat,n):
        RLE=[(k,len(tuple(g))) for k,g in itertools.groupby(dat)]
        tmp=tuple(zip(*RLE))
        return [list(g) for k,g in itertools.groupby((zip((sum(tmp[1][:i]) for i in range(len(tmp[1]))) ,(zip(*tmp)))),lambda x:x[1][0]!=n) if k]
    
    >>> fromDataToSplitRLE(data,1)
    [[(0, (0, 2))], [(3, (8, 3)), (6, (4, 2))], [(9, (0, 1))]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was tasked with counting the number of distinct strings in a column in
Is the memory from primitive data types (int, char,etc) immediately released once they leave
I have a table in mysql which stores (among other columns) a bitmask as
It appears that NHibernate cannot automap more than one IList of a given type
I have an object containing a date and a count. public class Stat {
What is the clearest way to comma-delimit a list in Java? I know several
EDIT: This was an old bug long since fixed in Scala 2.8 and later
I have to write a component that re-creates SQL Server tables (structure and data)
I’ve had a bit of feedback from some threat and vulnerability folks relating to
I am really used to doing grep -iIr on the Unix shell but I

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.