Question: 2. Write a Python function based on the following algorithm for randomly permuting the characters in a given string and return the resulting string. Repeat

 2. Write a Python function based on the following algorithm for

2. Write a Python function based on the following algorithm for randomly permuting the characters in a given string and return the resulting string. Repeat len(word) times Pick a random position i in the string,but not the last position. Pick a random position j > i in the string Swap the letters at positions j and Return the word Notes Since we can't actually swap letters in a Python string, we can (i) convert the string to a list of individual letters (string), (i) swap the letters in the list, and (ili) convert the resulting back to a string prior to returning it To accomplish step (i), we can use the Python list function: assume word is a string, then list(word) will return its individual characters as a list of strings To accomplish step (ii), assuming wordList is a list of strings, we con use the expression "join(wordList) to convert wordList to a string Paste your function definition with some sample outputs here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!