May-22-2019, 02:31 PM
(May-08-2019, 05:32 PM)DeaD_EyE Wrote: Quick and dirty solution with less Python knowledge:
hashable_data = tuple(set(ITERABLE))Mutable objects don't have a hash, because they can mutate.
Immutable objects doesn't change, so they have have a hash.
There is also a built-in type, called frozenset and yes, it does what it sounds like.
This is an immutable set, which has an hash.
You can make the test:
# will fail {set(): 42} # is ok {frozenset(): 42}
Try this:
df_sar['sar_details_sent_norm_trigrams_unique'] = df_sar['sar_details_sent_norm_trigrams_'].apply(lambda x: frozenset([trigram for sent in x for trigram in sent]))And you can remove the square brackets, then it's a generator expression, which is consumed by frozenset (saves memory).
Otherwise first a list from the set is created in memory, then it's applied to the dataframe.
df_sar['sar_details_sent_norm_trigrams_unique'] = df_sar['sar_details_sent_norm_trigrams_'].apply(lambda x: frozenset(trigram for sent in x for trigram in sent))
This is great - thank you.