Question
Python A permutation of a list or string is a rearrangement of the elements in the list or string. For example, given the list [1,2,3,4],
Python
A permutation of a list or string is a rearrangement of the elements in the list or string. For example, given the list [1,2,3,4], permutations would include [2,4,1,3], [4,3,1,2] and [3,2,4,1]. Likewise, given the string dome, permutations would include edom, emod and mode.
Write a function permutations() that takes a string argument, opens the file words.txt (provided on Blackboard) and returns a list consisting of all permutations of the string argument found in the file (if any). The original word should not be included in the returned list. The function may return the words in any order inside the list.
def permutations(word): return none
if __name__ == '__main__':
print('Testing permutations() for "veil": ' + str(permutations('veil'))) print('Testing permutations() for "tori": ' + str(permutations('tori'))) print('Testing permutations() for "dad": ' + str(permutations('dad'))) print('Testing permutations() for "ado": ' + str(permutations('ado')))Examples: Function Call Return Value permutations veil') evil', 'levi', 'live', vile' permutations 'tori') riot', 'trio' permutations dad') add' permutations ado
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started