I have the following list:
x = ['long stories about hard yarn',
'The bears',
'unpleasant',
'The bears endure tiring',
'The bears endure',
'tiring and unpleasant',
'long stories',
'hard yarn',
'tiring',
'The bears endure tiring and unpleasant']
I'm expecting the following sublist output:
[['The bears endure tiring and unpleasant', 'tiring and unpleasant', 'tiring'],
['The bears endure tiring and unpleasant',
'tiring and unpleasant',
'unpleasant'],
['The bears endure tiring and unpleasant',
'The bears endure tiring',
'tiring'],
['The bears endure tiring and unpleasant',
'The bears endure tiring',
'The bears endure',
'The bears'],
['long stories about hard yarn', 'long stories'],
['long stories about hard yarn', 'hard yarn']]
I wrote the code in the following way:
from itertools import combinations, permutations
perm = permutations(x, 2)
simlr = []
for i,j in list(perm):
if len(i) > len(j):
if check(i,j):
simlr.append([i,j])
simlr
Getting the following output:
[['long stories about hard yarn', 'long stories'],
['long stories about hard yarn', 'hard yarn'],
['The bears endure tiring', 'The bears'],
['The bears endure tiring', 'The bears endure'],
['The bears endure tiring', 'tiring'],
['The bears endure', 'The bears'],
['tiring and unpleasant', 'unpleasant'],
['tiring and unpleasant', 'tiring'],
['The bears endure tiring and unpleasant', 'The bears'],
['The bears endure tiring and unpleasant', 'unpleasant'],
['The bears endure tiring and unpleasant', 'The bears endure tiring'],
['The bears endure tiring and unpleasant', 'The bears endure'],
['The bears endure tiring and unpleasant', 'tiring and unpleasant'],
['The bears endure tiring and unpleasant', 'tiring']]
The above output is valid, but I need to get refined output (grouping) where every sublist has main large string following by respective substrings sorted.