Global name in Python

后端 未结 2 1906
别跟我提以往
别跟我提以往 2021-01-05 09:01

I want to find out whether two numbers N1 and N2 are the permutations of the same digits. For example 123 and 321

2条回答
  •  孤城傲影
    2021-01-05 09:52

    There is no need to do anything with global values here. Everything should be contained within the function.

    The problem is simply that you don't define arr1 or arr2 before you try appending to them. You need to define them in that function, along with s1, s2, k and fl.

    Edit I should add that your code is extremely unPythonic. All these while loops with incrementing counters should be replaced with for loops: for k in range(10) etc. But the first loop isn't even necessary - you should have arr1 = [0] * 10 and the same for arr2.

提交回复
热议问题