-1

I'm making anagram in python but when I call 'list'function, it doesn't work. please help. I'm tring to change 'str' to 'list' but it doesn't work. I really don't know why

def generate_anagram(s):
    a=s[0:len(s)-1]
    b=s[len(s)-1]
    if len(a)==1:
        return make(a,b)
    else:
        return make(generate_anagram(a),b)  

def make(s1,s2):
    list=[]
    l=len(s1)
    q=list(s1)
    w=list(s2)
    ss=""
    for i in range(l):
        if(len(q)>l):
            q.remove(w)
        q.insert(i,w)
        list+=q

    for i in range(len(list)):
        ss+=list[i]
    return ss


if __name__ == "__main__":

    print(generate_anagram("anagram"))
1
  • Because you've overwritten the built-in function list() with a variable name list Commented Apr 1, 2017 at 6:50

1 Answer 1

0

The code

list=[]
l=len(s1)
q=list(s1)
w=list(s2)

is problematic because the first line will "hide" the standard function list by creating a local variable named list. This means the last two lines are not calling the list function of Python.

Sign up to request clarification or add additional context in comments.

3 Comments

Can I ask one more? I want to make 'list[i]' to 'str' but, ss+=list[i] dosen't work.. how can I make list type to str type?
@babababam: in Python "".join(L) where L is a list of characters concatenates all of them and returns the resulting string.
Thank you! you are so kind!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.