Filter Anagram in Array in Python -


i'm trying go through array , delete elements aren't anagrams in python. here code wrote. logic seems fine can't seem it.

b = ['cat', 'dog', 'god', 'star', 'lap', 'act'] array=[] t=0 in b:     while t<len(b):         if ''.join(sorted(i))==''.join(sorted(b[t])):            array.append(i)         t+=1 print array 

just minor tweaks existing code should work.

b = ['cat', 'dog', 'god', 'star', 'lap', 'act'] array = [] t = 0 i, value in enumerate(b):     t = i+1     while t<len(b):         if ''.join(sorted(value))==''.join(sorted(b[t])):             array.extend([value, b[t]])         t+=1 print array ['cat', 'act', 'dog', 'god'] 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -