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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:10:36+00:00 2026-06-06T16:10:36+00:00

Given sequence : [1,A,B,C,2,F,K,L,5,6,P,I,E] The numbers represent items that I identify as headers, whereas

  • 0

Given sequence :

["1","A","B","C","2","F","K","L","5","6","P","I","E"]

The numbers represent items that I identify as headers, whereas the letters represent items that I identify as data. I want to associate them into groups like this.

1:A,B,C    
2:F,K,L    
5:    
6:P,I,E

I can easily achieve this using a foreach or while loop on the enumerator, but is there a LINQ’ish way to achieve this? This is a recurring pattern in my domain.

  • 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-06T16:10:38+00:00Added an answer on June 6, 2026 at 4:10 pm

    You can make use of a fold:

    var aggr = new List<Tuple<Int,List<String>>>();
    var res = sequence.Aggregate(aggr, (d, x) => {
        int i;
        if (Int32.TryParse(x, out i)) {
            var newDict = d.Add(new Tuple(i, new List<string>()));
            return newDict;
        } 
        else {
            var newDict = d[d.Count - 1].Item2.Add(x);
            return newDict;
        }
    }).ToDictionary(x => x.Item1, x => x.Item2);
    

    However, this doesn’t look so nice, since there’s lacking support for immutable values. Also, I couldn’t test this right now.

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

Sidebar

Related Questions

Given the following sequence: normal %(b)BOLD% normal I want to transform this into the
Given a sequence of data (it may have duplicates), a fixed-sized moving window, move
Given the following model, I want to index the fields (sequence,stock) class QuoteModel(models.Model): quotedate
I'm looking for an algorithm that given two permutations of a sequence (e.g. [2,
I need to generate a controlled sequence of pseudo-random numbers, given an initial integer
Given a sequence of trillion real numbers on a disk... How would you compute
If I am given the numbers [1,2,1] and I want to find the sum
Problem: you are given a sequence of numbers from 1 to n-1 with one
Given a positive integer sequence of numbers in an array with common difference 2
I'm looking for an algorithm to segment a sequence of positive numbers into n

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.