title: How to convert Array to Dictionary while keeping the same order Swift
body: <p>Hey I have been looking at some really good question on here. About how to convert a Array to a dictionary but the problem is that is doesn't keep the same order Example:</p>
  
  <pre><code>list = ["test", "test2", "test3"]
  </code></pre>
  
  <p>outPut: </p>
  
  <pre><code>listNewFromExt = ["test": "test","test3": "test3", "test2": "test2"]
  </code></pre>
  
  <p>Basically test3 is being switched places with test2</p>
  
  <p>Code:</p>
  
  <pre><code>let listNewFromExt = list.toDictionary{($0, $0)}
  
  extension Sequence {
   public func toDictionary&lt;K: Hashable, V&gt;(_ selector: (Iterator.Element) throws -&gt; (K, V)?) rethrows -&gt; [K: V] {
      var dict = [K: V]()
      for element in self {
          if let (key, value) = try selector(element) {
              dict[key] = value
          }
      }
  
      return dict
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Also if you could tell me how to just make the .values "nil" instead of a copy of the key that would be great lol.</p>