Advertisement
Hiteshw11

Two Lists To A Map Conversion

Nov 24th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.43 KB | Source Code | 0 0
  1. /* Write a function that converts a list of keys and a list of values into a map. */
  2.  
  3. void main() {
  4.   List<String> list1 = ['name', 'age'];
  5.   List<dynamic> list2 = ['Alice', 25];
  6.   print(listToMap(list1, list2));
  7. }
  8.  
  9. Map<String, dynamic> listToMap(List<String> list1, List<dynamic> list2) {
  10.   Map<String, dynamic> mapper = {};
  11.   for (int i = 0; i < list1.length; i++) {
  12.     mapper[list1[i]] = list2[i];
  13.   }
  14.   return mapper;
  15. }
  16.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement