0

R=[['dafdwsf','fafwfwe','fedfwefw','kmlknkfwe'],['cdcdcewfqedq','aasdecercre','hhkklkmlk','testing'],['nvnnkv','mmffwe','ljfljfwe']]

S=[['hhkklkmlk','cdcdcewfqedq'],['fwlkmfw','mmffwe','ljfljfwe'],['dafdwsf','fafwfwe','fedfwefw','kmlknkfwe']]

If have converted lists of lists to set of tuples

set(map(tuple,R))-set(map(tuple,S))

returns

{('cdcdcewfqedq', 'aasdecercre', 'hhkklkmlk','testing'),('nvnnkv', 'mmffwe', 'ljfljfwe')}

Im looking for ways to get :

{('aasdecercre','testing'),('nvnnkv')}

I have read here to sort the tuples before creating set but still not getting the desired output.

sr33kant
  • 35
  • 3

1 Answers1

0

You can flatten the lists R and S:

r = [item for sublist in R for item in sublist]

s = [item for sublist in S for item in sublist] (different ways to flatten a nested list here) and then create the sets using

x = set(tuple(r))-set(tuple(s)).

Then regroup all values based on parent list(this implementation depends on size of your lists/sets, if its only a few, this will work):

r2 = [ [i for i in j if i in x] for j in R]

and then convert to tuples:

r2 = [tuple(i) for i in r2 if len(i)>0]

SajanGohil
  • 960
  • 13
  • 26