how to group by function if one of the group has relationship with another one in the group?
Ho Yeung Lee
jobmattcon at gmail.com
Fri Jul 28 11:04:57 EDT 2017
actually i used in this application
if same color is neighbor like connected then group them
i use for segmentation of words in screen capture
https://stackoverflow.com/questions/45294829/how-to-group-by-function-if-any-one-of-the-group-members-has-neighbor-relationsh
i asked here too, but i do not know how to use partial and do not know what center is.
On Wednesday, July 26, 2017 at 2:06:08 PM UTC+8, ast wrote:
> "Ho Yeung Lee" <jobmattcon at gmail.com> a écrit dans le message de
> news:ef0bd11a-bf55-42a2-b016-d93f3b831860 at googlegroups.com...
> > from itertools import groupby
> >
> > testing1 = [(1,1),(2,3),(2,4),(3,5),(3,6),(4,6)]
> > def isneighborlocation(lo1, lo2):
> > if abs(lo1[0] - lo2[0]) == 1 or lo1[1] == lo2[1]:
> > return 1
> > elif abs(lo1[1] - lo2[1]) == 1 or lo1[0] == lo2[0]:
> > return 1
> > else:
> > return 0
> >
> > groupda = groupby(testing1, isneighborlocation)
> > for key, group1 in groupda:
> > print key
> > for thing in group1:
> > print thing
> >
> > expect output 3 group
> > group1 [(1,1)]
> > group2 [(2,3),(2,4]
> > group3 [(3,5),(3,6),(4,6)]
>
> Its not clear to me how you build the groups
>
> Why (1,1) is not in group2 since (1,1) is
> a neighbor to both (2,3) and (2,4) ?
More information about the Python-list
mailing list