I am learning python and tried the anagram generator exercise and then decided to try different methods of generating anagrams and then decided to generate sub anagrams. The problem I am having is that the lists need to be compared and then list_2 needs to be removed from list_1 to state whether it is a sub anagram, however this is not happening and when I run it the first letter is removed then one letter that is the same in both words. My code is below:
def sub_anagram(word_1, word_2):
#letters need to be sorted into alphabetical order
list_1 = [c for c in word_1] #turns the string into a list
#list_1.sort() #sorts the list alphabetically
print(list_1)
list_2 = [c for c in word_2] #turns the string into a list
#list_2.sort() #sorts the list alphabetically
print(list_2)
#then the lists get compared
#loop to check if any letters from list_2 are in list_1
for list_2 in list_1:
#removes the letters in list_1 that are in
list_1.remove(list_2) list_2
print(list_2)
print(list_1)
list_1[len(list_1)-1] #checks the length of the list
if list_2 == list_1:
print("It is a sub-anagram")#return true if it is a sub-anagram
else:
print("It is not a sub-anagram") #return false if not
print("Sub-Anagram Antics")
#user inputs two words
#user input word 1
word_1 = input("Enter a word: ")
#user input word 2
word_2 = input("Enter a word: ")
#call function
sub_anagram(word_1, word_2)