Omitting (if, else) Statements with Use Of Python Dictionary
· Tip:-
· We can omit the if, else statements with python dictionary.
· Code:-
def getDirection(direction):
conditionalDict = { 'Left' : 'Proceed Left', 'Right': 'Proceed Right'}
return conditionalDict.get(direction)
# Test Code
print getDirection('Right')
# Result : 'Proceed Right'
HTML Comment Box is loading comments...