Last active
April 7, 2017 17:36
-
-
Save rodrigodev/8794d49c4a2206e0a94b52d7a92a6cb8 to your computer and use it in GitHub Desktop.
Revisions
-
rodrigodev revised this gist
Apr 7, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,9 @@ def smart_group_by_nearest(distance, int_list): grouped_list[-1].append(x) else: grouped_list.append([x]) return grouped_list #remove small groups if wanted #return [x for x in grouped_list if len(x) > 1] if __name__ == "__main__": int_list = [5, 10, 12, 1, 10, 4] -
rodrigodev created this gist
Apr 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ def smart_group_by_nearest(distance, int_list): int_list.sort() grouped_list = [[int_list[0]]] for x in int_list[1:]: if x - grouped_list[-1][0] <= distance: grouped_list[-1].append(x) else: grouped_list.append([x]) return [x for x in grouped_list if len(x) > distance] if __name__ == "__main__": int_list = [5, 10, 12, 1, 10, 4] print smart_group_by_nearest(1, int_list)