Take groups of 5 strings from List

BlueChippy

I have a List<string> and I want to take groups of 5 items from it. There are no keys or anything simple to group by...but it WILL always be a multiple of 5.

e.g.

{"A","16","49","FRED","AD","17","17","17","FRED","8","B","22","22","107","64"}

Take groups of:

"A","16","49","FRED","AD"
"17","17","17","FRED","8"
"B","22","22","107","64"

but I can't work out a simple way to do it!

Pretty sure it can be done with enumeration and Take(5)...

Tim Schmelter

You can use the integer division trick:

List<List<string>> groupsOf5 = list
    .Select((str, index) => new { str, index })
    .GroupBy(x => x.index / 5)
    .Select(g => g.Select(x => x.str).ToList())
    .ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get elements from a list, by groups of 10? (or 5, or 3, etc)

From Dev

Take a segment from a list

From Dev

Storing a list of strings to a HDF5 Dataset from Python

From Dev

Getting groups as a list from arraylist

From Dev

Take From a List While Increasing

From Java

Finding Groups of Rearranged Strings from a txt With Strings on Seperate Lines

From Dev

Splitting a Python list into groups of 5 and then printing

From Dev

Python Remove List of Strings from List of Strings

From Dev

I'd'd like to take a list of strings, find them in another csv file and print a field from the matching line

From Dev

Filter a list of strings in powershell by a regex, then group and sort by one of the capture groups

From Dev

List all groups from members of a specified group

From Dev

Create Groups from a list of Objects in C#

From Dev

Showing a list of groups' titles from a JSON file

From Dev

Get all the Quickblox groups list from server

From Dev

Replacing groups of numbers from list (python)

From Dev

How to extract data from a list with multiple groups?

From Dev

Take a picture from html5

From Java

Remove empty strings from a list of strings

From Dev

take n elements from the front of the list in Prolog

From Dev

Pythonic way to take the only item from a list

From Dev

How to take last records from list

From Dev

Take a range of the elements by their indexes from a list

From Dev

Take data from one list to another

From Dev

take n elements from the front of the list in Prolog

From Dev

How to take multiple values from a python list?

From Dev

Removing characters from List of Strings

From Dev

Strings from files to tuples in list

From Dev

Subset data from a list of Strings

From Dev

Delete substrings from a list of strings

Related Related

  1. 1

    How to get elements from a list, by groups of 10? (or 5, or 3, etc)

  2. 2

    Take a segment from a list

  3. 3

    Storing a list of strings to a HDF5 Dataset from Python

  4. 4

    Getting groups as a list from arraylist

  5. 5

    Take From a List While Increasing

  6. 6

    Finding Groups of Rearranged Strings from a txt With Strings on Seperate Lines

  7. 7

    Splitting a Python list into groups of 5 and then printing

  8. 8

    Python Remove List of Strings from List of Strings

  9. 9

    I'd'd like to take a list of strings, find them in another csv file and print a field from the matching line

  10. 10

    Filter a list of strings in powershell by a regex, then group and sort by one of the capture groups

  11. 11

    List all groups from members of a specified group

  12. 12

    Create Groups from a list of Objects in C#

  13. 13

    Showing a list of groups' titles from a JSON file

  14. 14

    Get all the Quickblox groups list from server

  15. 15

    Replacing groups of numbers from list (python)

  16. 16

    How to extract data from a list with multiple groups?

  17. 17

    Take a picture from html5

  18. 18

    Remove empty strings from a list of strings

  19. 19

    take n elements from the front of the list in Prolog

  20. 20

    Pythonic way to take the only item from a list

  21. 21

    How to take last records from list

  22. 22

    Take a range of the elements by their indexes from a list

  23. 23

    Take data from one list to another

  24. 24

    take n elements from the front of the list in Prolog

  25. 25

    How to take multiple values from a python list?

  26. 26

    Removing characters from List of Strings

  27. 27

    Strings from files to tuples in list

  28. 28

    Subset data from a list of Strings

  29. 29

    Delete substrings from a list of strings

HotTag

Archive