Champak Posted March 21, 2022 Share Posted March 21, 2022 (edited) Let's say the following is my array, I need something that will look at the third column and return a 2d array without duplicates in the third column. Dec|four|Mon Jan|nine|Tue Mar|six|Wed Bus|five|Tue blue|four|Mon Jan|nine|Tue Mar|six|Sat Bus|five|Fri So this should be the result: Dec|four|Mon Jan|nine|Tue Mar|six|Wed Mar|six|Sat Bus|five|Fri I looked at _arrayunique, but it only returns a 1D array of the column I want to analyze for the duplicate entries. I searched but didn't find something like what I am after. Is this possible? Edited March 21, 2022 by Champak Link to comment Share on other sites More sharing options...
Subz Posted March 22, 2022 Share Posted March 22, 2022 (edited) Since you have Mar|six|Wed and Mar|six|Sat in the expected results, wouldn't you also have Bus|five|Tue? Or are you meaning that the first two columns do not have to be unique? Edited March 22, 2022 by Subz Link to comment Share on other sites More sharing options...
Champak Posted March 22, 2022 Author Share Posted March 22, 2022 Correct, first two don't have to be unique, just the third....but I need all columns returned. Link to comment Share on other sites More sharing options...
pixelsearch Posted March 22, 2022 Share Posted March 22, 2022 Maybe something like this ? #include <Array.au3> Opt("MustDeclareVars", 1) Local $aArray[][] = [ _ ["Dec","four","Mon"], ["Jan","nine","Tue"], ["Mar","six","Wed"], ["Bus","five","Tue"], _ ["blue","four","Mon"],["Jan","nine","Tue"], ["Mar","six","Sat"], ["Bus","five","Fri"] ] Local $iColSearch = 2, $aArray2 = _ArrayUnique2D($aArray, $iColSearch) _ArrayDisplay($aArray2, "Array Unique col " & $iColSearch) ;============================================= Func _ArrayUnique2D(ByRef $aArray, $iColSearch) Local $iRows = Ubound($aArray, $UBOUND_ROWS), $iCols = Ubound($aArray, $UBOUND_COLUMNS) Local $aArray2[$iRows][$iCols], $iRow = -1, $oDictionary = ObjCreate("Scripting.Dictionary") For $i = 0 To $iRows - 1 If Not $oDictionary.Exists($aArray[$i][$iColSearch]) Then ; key exists ? $oDictionary.Add($aArray[$i][$iColSearch], $i) ; key important, item not. $iRow += 1 ; 0+ For $j = 0 To $iCols - 1 $aArray2[$iRow][$j] = $aArray[$i][$j] Next EndIf Next ReDim $aArray2[$iRow + 1][$iCols] Return $aArray2 EndFunc Musashi and Subz 2 Link to comment Share on other sites More sharing options...
pixelsearch Posted March 22, 2022 Share Posted March 22, 2022 @Subz Glad you liked. It's you that should be liked 10 times for all the help you bring to so many people on this Forum. Link to comment Share on other sites More sharing options...
Champak Posted March 22, 2022 Author Share Posted March 22, 2022 Thanks, that's perfect. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now