Real christmas trees are a major fire risk

November Feature Articles
image here

If you want to minimize mess (and fire risk), go with an artificial tree

No one likes cleaning up the piles of needles from a natural tree. “No matter what you do, there’s going to be needles falling off a real tree,” said Chal Landgren, a professor in the department of horticulture at Oregon State University. If you want to avoid the mess, go with an artificial Christmas tree.

Get An Artificial Tree →
 
 
 

Try this:

myl=dict() with open('test.txt') as f :     for l in f:         l = l.rstrip()         try:             tags = l.split('/')[1]             myl.setdefault(tags,[])             myl[tags].append(l.split('/')[0])             for t in tags:                 myl.setdefault(t,[])                 myl[t].append( l.split('/')[0])         except:             pass keys=myl.keys() for k1 in keys:     for k2 in keys:         if len(set(k1).intersection(k2))==len(set(k1)) and k1!=k2:             myl[k1].extend([myk2v for myk2v in myl[k2] if myk2v not in myl[k1]])  print(myl)

Output

{'S': ['test', 'test', 'girl', 'house', 'wind'], 'SE': ['girl', 'house', 'wind'], 'E': ['girl', 'house', 'man', 'man', 'wind'], '': ['home', 'test', 'test', 'girl', 'house', 'wind', 'man', 'man'], 'SE123': ['house'], '1': ['house'], '2': ['house'], '3': ['house'], 'ES': ['wind', 'girl', 'house']}

In the last two for loops of the program, the set ofk1andk2are taken first, and then, the intersection of the two sets is compared. If the length of the intersection is equal to the length of setk1, the value of the keyk2should be in the keyk1, so the value of the keyk2is added to the keyk1.

 
Group Of GrafiKom™ Total Design