def scramble(s1,s2):
for c in set(s2):
if s1.count(c) < s2.count(c):
return False
return True
def scramble(s1,s2):
#your code here
for c in set(s2):
if s1.count(c) < s2.count(c):
return False
return True
from collections import Counter
def scramble(s1,s2):
# Counter basically creates a dictionary of counts and letters
# Using set subtraction, we know that if anything is left over,
# something exists in s2 that doesn't exist in s1
return len(Counter(s2)- Counter(s1)) == 0
def scramble(s1, s2):
return not any(s1.count(char) < s2.count(char) for char in set(s2))
(condition for element in iterable)
def scramble(s1,s2):
return all( s1.count(x) >= s2.count(x) for x in set(s2))
def scramble(s1,s2):
return all((s1.count(x) >= s2.count(x) for x in set(s2)))
def scramble(s1, s2):
# your code here
return all(s1.count(x) >= s2.count(x) for x in set(s2))
def scramble(s1, s2):
return all( s1.count(x) >= s2.count(x) for x in set(s2))
# your code here
def scramble(s1,s2):
dct={}
for l in s1:
if l not in dct:
dct[l]=1
else:
dct[l] +=1
for l in s2:
if l not in dct or dct[l] < 1:
return False
else:
dct[l] -= 1
return True
from collections import Counter
def scramble(s1,s2):
c1 = Counter(s1)
c2 = Counter(s2)
return not (c2 -c1).values()
from collections import Counter
scramble = lambda s1, s2: not Counter(s2) - Counter(s1)
scramble=lambda a,b,c=__import__('collections').Counter:not c(b)-c(a)
from collections import Counter
from operator import sub
def scramble(s1,s2):
return not sub(*map(Counter, (s2,s1)))
from collections import Counter
def scramble(s1,s2): return len(Counter(s2) - Counter(s1)) == 0
from collections import Counter
def scramble(s1, s2):
return (len(Counter (s2)-Counter (s1)) == 0)
def scramble(s1, s2):
from collections import Counter
return len(Counter(s2) - Counter(s1)) == 0
景越Python基础训练营QQ群
欢迎各位同学加群讨论,一起学习,共同成长!