Home > other >  Enumeration method error IndexError python3 anagram violence: list index out of range for answers
Enumeration method error IndexError python3 anagram violence: list index out of range for answers

Time:10-19

Two displacement, the first letter of the first word and the back of the letters swap places, recursive back until we find after rearrangement and the second word is the same word, return True, otherwise it returns False,

Don't understand the 98 lines that a=ss1 [I] have what problem, I am in python and TYPHON two word test, it is not possible is pop list is empty, it want to don't understand, is still in preliminary stage, the possible program itself has a problem,, please everyone a great god answers,

CodePudding user response:

Do you want to determine whether two words of the same letters? Just a different order that?

CodePudding user response:

reference 1st floor JMZL response:
do you want to determine whether two words of the same letters? Just a different order that?
well well only the number of letters in a different order

CodePudding user response:

reference max5173 reply: 3/f
change range (1, len (ss1)), because your first cycle I==0, so always execute the elif module
or as to the wrong start from 0 is equivalent to not change order to directly compare the s1 and s2

CodePudding user response:

Well, just didn't look closely, I had a running through the function, understand it, the problem is you of 109 lines, the loop execution to the first letter is' t ', return True is back to the 109 lines of function calls, and then continue to cycle, at that time the ss1 became [' o ', 'y', 'h', 'p', 'n'], ss2 became [' y ', 'p', 'h', 'o', 'n'], jump into your main program function call, so had been circulating, but the pointer inside the for loop is will sum up all the time, until the pointer is greater than 5, will be an error

CodePudding user response:

refer to the second floor niconiconi0831 response:
Quote: refer to 1st floor JMZL response:
do you want to determine whether two words of the same letters? Just a different order that?
well well only the number of letters in a different order

You directly put string sorting contrast can determine whether the same character string

CodePudding user response:

reference 5 floor max5173 reply:
well, you just didn't look closely, I had a running through the function, understand it, the problem is you of 109 lines, the loop execution to the first letter is' t ', return True is to go back to the 109 lines of function calls, and then continue to cycle, at that time the ss1 became [' o ', 'y', 'h', 'p', 'n'], ss2 became [' y ', 'p', 'h', 'o', 'n'], jump into your main program function call, so had been circulating, but the pointer inside the for loop is will sum up all the time, until the pointer is greater than 5, you will get an error
should also not from python - ypthon - tpyhon t equal to this into elif into python and yphon change once more into the second cycle is equal to the ah... Pointer to a for loop has been increased but you said is what meaning to solve!

CodePudding user response:

refer to 6th floor JMZL response:
Quote: refer to the second floor niconiconi0831 response:
Quote: refer to 1st floor JMZL response:
do you want to determine whether two words of the same letters? Just a different order that?
well well only the number of letters in a different order

You directly put string sorting contrast can determine whether the same character string
I write the same problem in different ways

CodePudding user response:

refer to the eighth floor niconiconi0831 response:
Quote: refer to the sixth floor JMZL response:
Quote: refer to the second floor niconiconi0831 response:
Quote: refer to 1st floor JMZL response:
do you want to determine whether two words of the same letters? Just a different order that?
well well only the number of letters in a different order

You directly put string sorting contrast can determine whether the same character string
I write the same problem in different way

That you now write is no repeat order contrast?

CodePudding user response:

references 9 f JMZL response:
Quote: refer to the eighth floor niconiconi0831 response:
Quote: refer to the sixth floor JMZL response:
Quote: refer to the second floor niconiconi0831 response:
Quote: refer to 1st floor JMZL response:
do you want to determine whether two words of the same letters? Just a different order that?
well well only the number of letters in a different order

You directly put string sorting contrast can determine whether the same character string
I write the same problem in different way

That you now write is no repeat order contrast?
well arranged

CodePudding user response:

refer to 7th floor niconiconi0831 response:
Quote: refer to the fifth floor max5173 reply:
well, didn't watch carefully, I had a running through the function, understand it, the problem is you of 109 lines, the loop execution to the first letter is' t ', return True is back to the 109 lines of function calls, and then continue to cycle, at that time the ss1 became [' o ', 'y', 'h', 'p', 'n'], ss2 became [' y ', 'p', 'h', 'o', 'n'], jump into your main program function call, so had been circulating, but the pointer inside the for loop is will sum up all the time, until the pointer is greater than 5, you will get an error
should also not from python - ypthon - tpyhon t equal to this into elif into python and yphon change once more into the second cycle is equal to the ah... Pointer to a for loop has been increased but you said is what meaning to solve!

For loop has a characteristic is, you at the back of the range (len (ss1) judgment only once, that is to say, you change the length of the ss1 in circulation, will not change, I pointer range in your code, I was 012345, increase the order,
1, I=0 ss1=python, ss2=TYPHON, perform the else
2, I=1 ss1=ypthon, ss2=TYPHON, execute the else
3, when I=2 ss1=tpyhon, ss2=TYPHON, perform elif, a layer of permutation function called again, this time return is True, it doesn't make any sense, at that time, ss1=python, ss2=yphon
4, when I=3 ss1=oyhpn, ss2=yphon, perform the else (your question in this step, this is what is called a pointer I will continue to increase)
5, when I=4 ss1=nyhpo, ss2=yphon, perform the else
6, I=5, an error, because your ss1 length with only 5, so will make, also is your 98 lines of code
If still not clear, and can I private chat

CodePudding user response:

11 references max5173 response:
Quote: refer to 7th floor niconiconi0831 response:

nullnullnullnullnullnullnullnullnull
  • Related