Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def perms(string): if len(string) == 0: return [''] prevList = perms(string[1:len(string)]) nextList = [] for i in range(0,len(prevList)): for j in range(0,len(string)): newString = prevList[i][0:j]+string[0]+prevList[i][j:len(string)-1]

def perms(string): if len(string) == 0: return [''] prevList = perms(string[1:len(string)]) nextList = [] for i in range(0,len(prevList)): for j in range(0,len(string)): newString = prevList[i][0:j]+string[0]+prevList[i][j:len(string)-1] if newString not in nextList: nextList.append(newString) return nextList

I want to fix this function so instead of returning a list of permutations it will return a set. the objective of the above function is to recursively reutrn Given a string s, return a set of all possible permutations of the letters in s.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions