Advertisement
Hiteshw11

Merge Two Lists In A Map

Nov 22nd, 2024
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.46 KB | Source Code | 0 0
  1. /* Write a Dart function that takes two lists of equal length, one with keys and one with values, and returns a map created from these lists. */
  2.  
  3. void main() {
  4.   List<String> keys = ['name','age','city'];
  5.   List<dynamic> values =['Alice',25,'New York'];
  6.   print(merging(keys,values));
  7. }
  8.  
  9. Map<String,dynamic> merging(List<String> k,List<dynamic> v)
  10. {
  11. Map<String,dynamic> abc = {};
  12.  
  13.  
  14. for(int i=0;i<k.length;i++)
  15. {
  16. abc[k[i]]=v[i];
  17. }
  18.  
  19. return abc;
  20. }
  21.  
  22.  
  23.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement