class ExtendedString(str):
def __init__(self, s):
self.s = s
def __eq__(self, other):
if len(self.s) > len(other.s):
return other.s in self.s
else:
return self.s in other.s
def __ne__(self, other):
if len(self.s) > len(other.s):
return other.s not in self.s
else:
return self.s not in other.s
def __hash__(self):
return super(str, self).__hash__()
list1 = ['Вася.пидор', 'Петя.гной', 'Маша.шлюха', 'Саша.блядь', 'пека', 'йоба']
list2 = ['Вася', 'Петя', 'йоба']
es_list1 = [ExtendedString(s) for s in list1]
es_list2 = [ExtendedString(s) for s in list2]
print(list1)
print(list2)
print([s for s in es_list1 if s not in es_list2])
Y2xhc3MgRXh0ZW5kZWRTdHJpbmcoc3RyKToKICAgIGRlZiBfX2luaXRfXyhzZWxmLCBzKToKICAgICAgICBzZWxmLnMgPSBzCgogICAgZGVmIF9fZXFfXyhzZWxmLCBvdGhlcik6CiAgICAgICAgaWYgbGVuKHNlbGYucykgPiBsZW4ob3RoZXIucyk6CiAgICAgICAgICAgIHJldHVybiBvdGhlci5zIGluIHNlbGYucwogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBzZWxmLnMgaW4gb3RoZXIucwoKICAgIGRlZiBfX25lX18oc2VsZiwgb3RoZXIpOgogICAgICAgIGlmIGxlbihzZWxmLnMpID4gbGVuKG90aGVyLnMpOgogICAgICAgICAgICByZXR1cm4gb3RoZXIucyBub3QgaW4gc2VsZi5zCiAgICAgICAgZWxzZToKICAgICAgICAgICAgcmV0dXJuIHNlbGYucyBub3QgaW4gb3RoZXIucwoKICAgIGRlZiBfX2hhc2hfXyhzZWxmKToKICAgICAgICByZXR1cm4gc3VwZXIoc3RyLCBzZWxmKS5fX2hhc2hfXygpCgpsaXN0MSA9IFsn0JLQsNGB0Y8u0L/QuNC00L7RgCcsICfQn9C10YLRjy7Qs9C90L7QuScsICfQnNCw0YjQsC7RiNC70Y7RhdCwJywgJ9Ch0LDRiNCwLtCx0LvRj9C00YwnLCAn0L/QtdC60LAnLCAn0LnQvtCx0LAnXQpsaXN0MiA9IFsn0JLQsNGB0Y8nLCAn0J/QtdGC0Y8nLCAn0LnQvtCx0LAnXQoKZXNfbGlzdDEgPSBbRXh0ZW5kZWRTdHJpbmcocykgZm9yIHMgaW4gbGlzdDFdCmVzX2xpc3QyID0gW0V4dGVuZGVkU3RyaW5nKHMpIGZvciBzIGluIGxpc3QyXQoKcHJpbnQobGlzdDEpCnByaW50KGxpc3QyKQpwcmludChbcyBmb3IgcyBpbiBlc19saXN0MSBpZiBzIG5vdCBpbiBlc19saXN0Ml0p
['Вася.пидор', 'Петя.гной', 'Маша.шлюха', 'Саша.блядь', 'пека', 'йоба']
['Вася', 'Петя', 'йоба']
['Маша.шлюха', 'Саша.блядь', 'пека']