Pregunta de entrevista de Meta
# Question 3:
# Complete a function that returns a list containing all the mismatched words (case sensitive) between two given input strings
# For example:
# - string 1 : "Firstly this is the first string"
# - string 2 : "Next is the second string"
#
# - output : ['Firstly', 'this', 'first', 'Next', 'second']
Respuestas de entrevistas
def findDif(s1,s2):
set1=set(s1.split())
set2=set(s2.split())
return set1 ^ set 2
string1 = "Firstly this is the first string"
string2 = "Next is the second string"
s1 = set(string1.split())
s2 = set(string2.split())
ls = sorted(list(s1.symmetric_difference(s2)))
print("common words list: ",s1&s2)
print("uncommon words list: ",ls)
print(list(set(A.split()).symmetric_difference(set(B.split()))))
### solution:
def return_mismatched_words(str1, str2):
# Write your code here
str1 = str1.split()
str2 = str2.split()
words = str1 + str2
mismatched_words = []
for word in words:
if words.count(word) < 2:
mismatched_words.append(word)
return mismatched_words
def mismatched_words(string1, string2):
string1 = set(string1.split())
string2 = set(string2.split())
return list(string1 - string2) + list(string2 - string1)
def findDif(s1,s2):
l1=s1.split()
l2=s2.split()
l3= set(l1+l2)
for i in l1:
for j in l2:
if l1[i]==l2[j]:
l3.remove(l1[i])
return l3