1

New to dart, with origin from python. One thing I cannot find native support for is to be able to group an Iterable by a defined key. In python there is a very nice support from the itertools package (https://docs.python.org/3.8/library/itertools.html#itertools.groupby). What I want to achieve can be described in pseudo code.

a = [
  {
    x: 1,
    y: 1,
  },
  {
    x: 1,
    y: 2,
  },
  {
    x: 2,
    y: 3,
  },
  {
    x: 2,
    y: 4,
  }
]

for group, items in groupby(a, key: item['x']):
  print('$group : $items')

Expected output:

1 : {x:1, y: 1}, {x:1, y:2}
2 : {x:2, y: 3}, {x:2, y:4}
pjotr_dolphin
  • 1,207
  • 9
  • 34
  • 1
    see here: https://stackoverflow.com/questions/54029370/flutter-dart-how-to-groupby-list-of-maps/54036449 – Alex Radzishevsky Mar 10 '20 at 23:08
  • Does this answer your question? [Flutter/Dart how to groupBy list of maps](https://stackoverflow.com/questions/54029370/flutter-dart-how-to-groupby-list-of-maps) – Kevin Moore Mar 12 '20 at 01:51

0 Answers0