如何反转 Map <String, List<String>> Flutter 中的值?

How to Reverse Values in Map <String, List<String>> Flutter?

我有

Map<String,List<String>> myMap = {'1': ['A','B','C'], '2': ['D','E','F'], '3': ['G','H','I'] };

我想知道如何反转列表值。这就是我想要实现的目标:

Map<String,List<String>> myMap = {'1': ['C','B','A'], '2': ['F','E','D'], '3': ['I','H','G'] };

你可以这样做:

 void main() {
      Map<String,List<String>> myMap = {'1': ['A','B','C'], '2': ['D','E','F'], '3': ['G','H','I'] };
      
      Map<String,List<String>> reversedMap = {}; 
      
      myMap.forEach((key,value) {
        reversedMap[key] = value.reversed.toList();
      });
      
      print(reversedMap);
    }

输出:

{1: [C, B, A], 2: [F, E, D], 3: [I, H, G]}
data.map((key, value) => MapEntry(key, value.reversed.toList()));

注意:这会生成一张新地图。在评论中查看更多内容。