forked from fenyx-it-academy/Class4-PythonModule-Week2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment4Week2.py
More file actions
34 lines (29 loc) · 1.53 KB
/
assignment4Week2.py
File metadata and controls
34 lines (29 loc) · 1.53 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
# 4.
# 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']
word1=input("enter a 1.word: ")
word2=input("enter a 2.word: ")
s1 = set(word1) # 1.kelimeyi set e convert ettim.
s2 = set(word2) # 2.kelimeyi set e convert ettim.
k = s1.intersection(s2) # Shared letters between two words. | print(s1&s2)
klist = list(k) # kesisim set ini list e convert ettim.
klist.sort() # listeyi sort ettim.
str1 = ''.join(klist) # listenin item lerini str e convert ettim.
f1 = s1.difference(s2) # s1 fark s2. | print(s1-s2)
flist1 = list(f1) # f1 set ini list e convert ettim.
flist1.sort() # listeyi sort ettim.
str2 = ''.join(flist1) # listenin item lerini str e convert ettim.
f2 = s2.difference(s1) # s2 fark s1. | print(s2-s1)
flist2 = list(f2) # f2 set ini list e convert ettim.
flist2.sort() # listeyi sort ettim.
str3 = ''.join(flist2) # listenin item lerini str e convert ettim.
result_list = [str1, str2, str3] # olusan resultlari bir listede topladim.
print(result_list)