daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jul 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var dict = ["B": "16", "1": "A","N": "5", "K": "V", "A": "12"]
  2. var dict2 = ["C": "1", "A": "1", "E": "0","B": "Q", "16": "B"]
  3.  
  4. var keyArray = Array(dict3.keys.sorted())
  5. var valueArray = Array(dict.values.sorted())
  6. var temp = ""
  7. for item in 0..<keyArray.count {
  8.     for item2 in 0..<valueArray.count {
  9.         if keyArray[item] == valueArray[item2] {
  10.             let tmp = valueArray[item2]
  11.             let s1 = dict2[tmp]
  12.             let s2 = dict[s1!]
  13.             dict2[s2!] = s2
  14.             dict[s1!] = s1
  15.         }
  16.     }
  17. }
  18. print("dict:", dict)
  19. print("dict2:", dict2)
  20.  
  21. /*
  22. Output:
  23. dict: ["B": "B", "1": "1", "K": "V", "N": "5", "A": "12"]
  24. dict2: ["B": "Q", "A": "A", "16": "16", "C": "1", "E": "0"]
  25. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top