Skip to content

Instantly share code, notes, and snippets.

@tailorvj
Created April 7, 2020 08:05
Show Gist options
  • Save tailorvj/9c37caf8cebb26ee12d1f65890ee6b47 to your computer and use it in GitHub Desktop.
Save tailorvj/9c37caf8cebb26ee12d1f65890ee6b47 to your computer and use it in GitHub Desktop.
Dart example: Iterating through a Map
void main(){
Map<String, int> scores = {'Bob': 300};
print('Initial state of the scores Map: $scores');
for (var key in ['Bob', 'Rohan', 'Sophena']) {
scores.putIfAbsent(key, () => key.length);
}
for (MapEntry entry in scores.entries){
print('scores[\'${entry.key}\']: ${entry.value}');
}
List listOfKeys = scores.keys.toList();
print('list of keys: $listOfKeys');
List listOfValues = scores.values.toList();
print('list of values: $listOfValues');
Map mapFromIterables = Map.fromIterables(listOfKeys, listOfValues);
print('map from Iterables: $mapFromIterables');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment