[swift-users] Mapping a Dictionary to a Dictionary?
Jens Alfke
jens at mooseyard.com
Wed Aug 31 15:47:32 CDT 2016
That’s going to be quite slow, like O(n^2), since it copies the dictionary every time it adds a key to it.
It also seems more complicated than the simple for-loop implementation; but then, I’m not a functional-language programmer.
// here’s how I’d do it; not tested in a playground
var dict2 = [Key:Value](minCapacity: dict1.count)
for (k,v) in dict1 {
let (k1,v1) = xform(k,v)
dict2[k1] = v1
}
—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160831/8a877002/attachment.html>
More information about the swift-users
mailing list