Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fabrum

macrumors member
Original poster
Jan 15, 2021
47
3
Is there some software that can take a Dictionary of key: value pairs and find all the duplicate keys? The dataset was input manually and a mistake was made somewhere in a long list of data. All we can think to do is to copy the Dictonary to Pages and use the Find feature to check each key one by one.
 

casperes1996

macrumors 604
Jan 26, 2014
7,492
5,664
Horsens, Denmark
A Swift dictionary cannot have duplicates and if there are duplicate keys it will just see it as changing the value belonging to said key. So if you just create a Swift dictionary, runt through your values inserting it there you have a duplicate free version.


If you just want to find them and not remove them, you can similarly use a hashed lookup. Just have a dict that maps key to "foundIndices [Int]" and then update the corresponding array with the index through the keys array. Then you can filter out all the values arrays don't have 2+ elements
 
  • Like
Reactions: Madd the Sane
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.