forked from fenyx-it-academy/Class7-Python-Module-Week2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.py
More file actions
27 lines (20 loc) · 774 Bytes
/
Q3.py
File metadata and controls
27 lines (20 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ### 3.
# Write a program that takes in two words as input and returns a list containing three elements, in the following order:
# - Shared letters between two words.
# - Letters unique to word 1.
# - Letters unique to word 2.
# Each element of the output should have unique letters, and should be alphabetically sorted. Use set operations. The strings will always be in lowercase and will not contain any punctuation.
# ```
# Example
# Input1>>> "sharp"
# Input2>>> "soap"
# Output>>> ['aps', 'hr', 'o']
def two_words(w1, w2):
w1=set(w1)
w2=set(w2)
lis=[]
lis.append ("".join (sorted (w1& w2 )) )
lis.append ("".join (sorted (w1- w2 )) )
lis.append ("".join (sorted (w2-w1 )) )
return lis
print (two_words("sharp","soap") )