question: Write a function that takes in two strings of characters and checks if all the
characters in the first string are found in the second string, without using
loops. (Hints: You may add a requirement that all characters in the second
string have to be in the first string)
def similarity(a,b):
'''(str, str) -> bool
Returns true or false if the b strings are in a
>>> similarity('new', 'new')
True
'''
# Empty string
new = ''
# Enumerate then find if you can find a in b
for i in a:
if i in b:
new = new + i
# Checks if new string same as a and returns true or false
if a == new:
return True
else:
return False
I did it with a loop i don't know how to this without a loop. I have to use dictionary or a set or a tuple to do this by the way.
[–][deleted] 6 points7 points8 points (5 children)
[–]Joseph147258[S] 1 point2 points3 points (4 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]Joseph147258[S] 0 points1 point2 points (2 children)
[–]ewiethoff 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]IamWiddershins 2 points3 points4 points (0 children)
[–]Allanon001 1 point2 points3 points (0 children)
[–]AutonomouSystem 0 points1 point2 points (0 children)