'str' object has no attribute 'intersection' and unhashable set

dieter dieter at handshake.de
Thu Oct 6 03:05:22 EDT 2016


meInvent bbird <jobmattcon at gmail.com> writes:
> ...
> is there any algorithm tutorials or books or external library that
> can have a better result for finding repeated lines as group in grouping 
> application

I do not yet understand your problem (and still am not ready to
look at your code).

When I need grouping for elements based on some feature ("F(elem)") I usually
use:

groups = {}
for elem in elements:
  feature = F(elem)
  fg = groups.get(feature)
  if fg is None: groups[feature] = fg = []
  fg.append(elem)

After this look, the dict "groups" maps features to the list
of elements with the corresponding feature.

For this to work, the features must be hashable.
If they are not naturally, I derive a consistent (same feature
leads to same representation) hashable representation for them
and use that for the grouping.




More information about the Python-list mailing list