Skip to content

Commit 40b0b19

Browse files
author
Sanjay Pradeep Kumar
committedMay 26, 2019
Update WhatIsZip.py
Covering other use cases.
1 parent 8c51c07 commit 40b0b19

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed
 

‎Zip/WhatIsZip.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,33 @@
5252
finalOp = {}
5353

5454
def needOutput(sub, professors):
55-
finalOp = dict(zip(sub, professors))
56-
for i in sub:
57-
if i in finalOp:
58-
pass
59-
else:
60-
finalOp[i] = None
61-
return finalOp
55+
if len(sub) > len(professors):
56+
finalOp = dict(zip(sub, professors))
57+
finalOp = includedMissedEleement(finalOp, sub)
58+
return finalOp
59+
elif len(professors) > len(sub):
60+
finalOp = dict(zip(professors, sub))
61+
finalOp = includedMissedEleement(finalOp, professors)
62+
return finalOp
63+
else:
64+
return dict(zip(sub, professors))
65+
66+
67+
def includedMissedEleement(op, listToCheck):
68+
for i in listToCheck:
69+
if i not in op:
70+
op[i] = None
71+
return op
6272

6373
desiredOutput = needOutput(subject, teachernames)
64-
print(desiredOutput)
74+
print(desiredOutput)
75+
76+
# the above output is desired only in case of more subjects than teachers.
77+
78+
# what if there're more teachers than subjects.
79+
80+
subject = ['Tamil', 'English']
81+
teacherNames = ['Ram', 'Tamanna', 'Lita']
82+
83+
finaOutput = needOutput(subject, teacherNames)
84+
print(finaOutput)

0 commit comments

Comments
 (0)