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 pathShatha_W2_Q3_v2
More file actions
70 lines (53 loc) · 1.29 KB
/
Shatha_W2_Q3_v2
File metadata and controls
70 lines (53 loc) · 1.29 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
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']
```
"""
import functools
#str = ""
str_sort = ""
global final_lst
final_lst = []
global lst
lst = []
st1 = {}
st2 = {}
st3 = {}
st4 = {}
st5 = {}
st6 = {}
def lst_insertion (st6):
import functools
lst = []
str =""
lst = list(st6)
str = functools.reduce(lambda x,y : x+y, lst) #converts list to string
# str_sort = sorted(str)
str_sort = ''.join(sorted(str))
final_lst.append(str_sort)
####################################################
str1 = input("Enter first word ")
str2 = input("Enter second word ")
st1 = set(str1)
st2 = set(str2)
st6 = st1&st2
lst = list(st6)
lst_insertion(lst)
st3 =(st1^st2)
st5 = st3 - st2
lst = list(st5)
lst_insertion(lst)
st4 = st3 - st1
st5 = st3 - st2
lst = list(st4)
lst_insertion (lst)
print(final_lst)
#######################################