def isAna(w1,w2):
if (sorted(w1) == sorted(w2)):
return True
else:
return False
def stringAnagram(dictionary, query):
total = []
for q in query:
count = 0
for d in dictionary:
result = isAna(q,d)
if result == True:
count += 1
else:
pass
total.append(count)
return total
dic = ['listen', 'tow', 'silent', 'lisent', 'two', 'abc', 'no', 'on']
que = ['two', 'bca', 'no', 'listen']
stringAnagram(dic,que)
def testing(q,d):
print(q,d)
count = 0
arr = [sorted(q) == sorted(d) for q in que for d in dic]
for a in len(q):
arr.split( )
from collections import Counter
arr = [(q) for q in que for d in dic if ((sorted(q) == sorted(d)) == True)]
c_a = list(Counter(arr).values())
c_a
dq = dict(Counter(que))
type(dq)
[{q: += 1} for q in que for d in dic if ((sorted(q) == sorted(d)) == True)]
dq
for q in que:
for d in dic:
if sorted(q) == sorted(d):
dq[q] += 1
else:
pass
dq
dq = dict(zip(que, [0]*len(que)))
dq
def stringAnagram(dictionary, query):
dq = dict(zip(query, [0]*len(query)))
for q in query:
for d in dictionary:
if len(q) == len(d):
if sorted(q) == sorted(d):
dq[q] +=1
# else:
# pass
# print(q,d)
#
# pass
# elif sorted(q) == sorted(d):
# dq[q] += 1
# else:
# pass
return list(dq.values())