社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python中的buggy置换

hck007 • 5 年前 • 1743 次点击  

我已经为排列编写了java代码,但未能翻译成python。它们都是传递值,但我不明白为什么。输出给我 [[1, 2, 3], [1, 2, 3], [1, 2, 3enter code here]]

def permutation(nums):
    nums.sort()
    ans = []
    backTrack([], ans, nums)
    return ans

def backTrack(tempList, ans, nums):
    if len(tempList) == len(nums):
        newList = tempList[:]
        ans.append(newList)
    else:
        for i in range(len(nums)):
            if nums[i] in tempList:
                continue
            tempList.append(nums[i])
            backTrack(tempList, ans, nums)
            tempList = tempList[:-1]

ans = permutation([1, 2, 3])
print(ans)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46661
 
1743 次点击  
文章 [ 1 ]  |  最新文章 5 年前