title: Swift: convert [Dictionary<String, [String : Double]>.Element] to [String : [String : Double]]
body: <p>I have this JSON string:</p>
  <pre><code>[
      {
          &quot;name&quot;: &quot;first_category&quot;,
          &quot;model&quot;: {
              &quot;OK&quot;: 0.49404761904761907,
              &quot;NOPE&quot;: 0.48214285714285715
          }
      },
      {
          &quot;name&quot;: &quot;second_category&quot;,
          &quot;model&quot;: {
              &quot;YOP&quot;: 0.389338593,
              &quot;GO&quot;: 0.20420894
          }
      }
  ]
  </code></pre>
  <p>I have created this struct to decode it:</p>
  <pre><code>struct JSONModel: Codable {
      let name: String
      let model: [String: Double]
  }
  </code></pre>
  <p>The decoding:</p>
  <pre><code>let decodedModel = try? decoder.decode([JSONModel].self, from: Data(jsonString.utf8))
  </code></pre>
  <p>It correctly fills the array as expected, but now I would like to use this array to create a dictionary whose keys would be the <code>JSONModel</code> names, and values the models. This is what I expect to get:</p>
  <pre><code>[
      &quot;first_category&quot;: [
          &quot;OK&quot;: 0.49404761904761907, 
          &quot;NOPE&quot;: 0.4821428571428571
      ],
      &quot;second_category&quot;: [
          &quot;YOP&quot;: 0.389338593, 
          &quot;GO&quot;: 0.20420894
      ]
  ]
  </code></pre>
  <p>So I tried this:</p>
  <pre><code>let simplifiedModel: [String: [String: Double]] = decodedModel.flatMap { [$0.name: $0.model] }
  </code></pre>
  <p>But I'm getting this error:</p>
  <blockquote>
  <p>Cannot convert value of type '[Dictionary&lt;String, [String : Double]&gt;.Element]' to closure result type '[String : [String : Double]]'</p>
  </blockquote>
  <p>What should I do instead?</p>
  <p>Thank you for your help</p>